next up previous
Next: 7 Graph algorithms Up: Communication-Efficient Parallel Algorithms Previous: 5 Tree contraction

6 Treefix computations

 

This section presents a generalization of the parallel prefix computation to binary trees. We present two kinds of treefix computations--rootfix and leaffix--and show how they can be implemented by an tex2html_wrap_inline1613 -step conservative algorithm that uses tex2html_wrap_inline1615 space, where n is the number of nodes in the input tree. As we shall see in Section 7, treefix computations can greatly simplify the description of many parallel graph algorithms in the literature, and moreover, treefix computations can be performed by conservative algorithms.

We begin with a definition of treefix computation. Definition. Let tex2html_wrap_inline1619 be a domain with a binary associative operation tex2html_wrap_inline1621 and an identity tex2html_wrap_inline1623 . Let T be a rooted, binary tree in which each vertex tex2html_wrap_inline1627 has an assigned input value tex2html_wrap_inline1629 . The rootfix problem is to compute for each vertex tex2html_wrap_inline1631 with parent j, the output value tex2html_wrap_inline1635 , where tex2html_wrap_inline1637 if i is the root. The leaffix problem is to compute for each vertex tex2html_wrap_inline1641 with left child j and right child k, the output value tex2html_wrap_inline1647 , where tex2html_wrap_inline1649 if i has no left child and tex2html_wrap_inline1653 if i has no right child. Simple examples of treefix problems are computing the depth of each vertex in a rooted binary tree and computing the size of each subtree. These and other examples appear in the next section.

Like the prefix computation on lists, treefix computations can be performed directly on the contraction tree. For simplicity, however, we describe a recursive version.

theorem565

Proof: Both treefix computations are performed by executing a single contraction step on the input tree T to produce a contracted tree tex2html_wrap_inline1673 . Each node in tex2html_wrap_inline1675 is assigned an input value, and the treefix computation is executed recursively on tex2html_wrap_inline1677 . The contracted tree tex2html_wrap_inline1679 is then expanded to yield T once again, and the output value of each node in T is computed from the input values of T and the output values of tex2html_wrap_inline1687 .

The algorithm for leaffix is based on each node i maintaining a value tex2html_wrap_inline1691 which has the form tex2html_wrap_inline1693 , where tex2html_wrap_inline1695 are elements of the domain, and the character `` tex2html_wrap_inline1697 '' represents symbolically a slot to be filled in with a value. The number of slots is equal to the number of children of the node, and each slot corresponds to a specific child. When a parent and child pair during the course of the leaffix algorithm, the value of the child is substituted into the corresponding slot in the value of its parent. For example, suppose node i pairs with its right child j, where the value of i is tex2html_wrap_inline1705 and the value of j is tex2html_wrap_inline1709 . The value tex2html_wrap_inline1711 of the merged node k is computed from tex2html_wrap_inline1715 and tex2html_wrap_inline1717 by substituting tex2html_wrap_inline1719 into the second slot in tex2html_wrap_inline1721 , yielding the value tex2html_wrap_inline1723 . The tex2html_wrap_inline1725 operations are carried out immediately so that tex2html_wrap_inline1727 has the proper form.

The leaffix algorithm initializes each node i by tex2html_wrap_inline1731 , tex2html_wrap_inline1733 , or tex2html_wrap_inline1735 depending on the number of children of node i. The algorithm then proceeds as follows. At the end of a contraction step, each node k in tex2html_wrap_inline1741 that results from the merging of parent i and child j computes its value tex2html_wrap_inline1747 by substituting tex2html_wrap_inline1749 into the appropriate slot of tex2html_wrap_inline1751 . The leaffix algorithm is then performed recursively on tex2html_wrap_inline1753 using the s values as inputs and yielding y values as output. (The y values contain no slots and are simply elements of the domain tex2html_wrap_inline1761 .) During the expansion step, the parent node i sets tex2html_wrap_inline1765 . Each child node j gets its output value tex2html_wrap_inline1769 by substituting the y values of its children into the slots of tex2html_wrap_inline1773 .

In the rootfix algorithm, each node i maintains a value tex2html_wrap_inline1777 , as in the leaffix algorithm, but each tex2html_wrap_inline1779 now has the general form tex2html_wrap_inline1781 , and the slot of a node corresponds to the node's parent. The rootfix algorithm initializes each node i by tex2html_wrap_inline1785 , except for the root r which performs tex2html_wrap_inline1789 . After the pairs have been determined for the contraction step, each node j that is the child in a pair, and which itself has a child, substitutes tex2html_wrap_inline1793 in the appropriate slot of its child's value. At the end of a contraction step, each node k in tex2html_wrap_inline1797 that resulted from the merging of parent i and child j computes its value by tex2html_wrap_inline1803 . The rootfix algorithm is then performed recursively on tex2html_wrap_inline1805 , yielding y values as output. During the expansion step, the parent node i sets tex2html_wrap_inline1811 . Each child node j gets its output value tex2html_wrap_inline1815 by substituting tex2html_wrap_inline1817 into the slot of tex2html_wrap_inline1819 .

The time and space bounds claimed in the theorem are apparent by inspection. Each step of a treefix algorithm adds only a constant amount of work to a corresponding step in the tree contraction and expansion algorithms. The additional space required by the treefix algorithms is the tex2html_wrap_inline1821 space per node for the x, y, and s values.


to .667emto .667em



next up previous
Next: 7 Graph algorithms Up: Communication-Efficient Parallel Algorithms Previous: 5 Tree contraction



Bruce Maggs
Thu Jul 25 19:12:36 EDT 1996