| Linear-time breadth-first tree algorithms An exercise in the arithmetic of folds and zips (1992) | |||||||||||||||
Abstract | |||||||||||||||
| This is a paper about an application of the mathematics of zip, fold (reduce) and accumulate (scan) operations on lists. It gives an account of the derivation of a linear-time breadth-first enumeration function, and of a subtle and efficient breadth-first tree labelling function. 1 Breadth-first ordering The algorithms which are developed in this paper relate trees to lists in a way that respects `breadth-first' ordering on the nodes of a tree. This is the order in which nodes nearer the root are considered to be earlier and -- perhaps arbitrarily, but for definiteness -- those at the same depth from the root are ordered lexicographically by the the `left to right' seniority of their line of descent. This paper works with rose trees, in which each node has an arbitrary finite number of immediate descendants tree ff = = ta where ta ::= Nd ff [ta] root(Nd a ts) = a subs(Nd a ts) = ts and will develop implementations of the breadth-first scanning and labelling functions bfs and lab b... | |||||||||||||||
Publication details | |||||||||||||||
| |||||||||||||||