Applications of Parallel Tree Contraction 1 Parallel Tree Contraction

18.434: Seminar in Theoretical Computer Science
Applications of Parallel Tree Contraction
Samuel Yeom
1
April 28, 2015
Parallel Tree Contraction
Recall the parallel tree contraction algorithm on a binary tree.
1. Every node randomly picks one of its neighbors.
• Leaves always pick their parents.
• Nodes with 1 child pick its parent or its child with probability 1/2 each.
– If the root has 1 child, it always picks its child.
• Nodes with 2 children pick either of its children with probability 1/2 each.
2. If two nodes picked each other, the child node is merged into the parent node, and
the parent node “inherits” any children that the child node had. (Note that only
nodes with 0 or 1 child can be merged into another node.)
3. Repeat steps 1 and 2 recursively until only the root is left.
We have shown previously that this takes O(log n) steps with high probability.
2
Expression Evaluation
We want to evaluate an expression given as a binary tree.
• Every leaf contains a value.
• Every other node has two children and contains an operator (addition, subtraction,
or multiplication).
We evaluate the expression by using tree contraction.
• Assign expressions to every node.
– The expression of a leaf is simply the value that it contains.
– Write L + R, L − R, or L × R for the operators, where L and R are the values
of the expressions in the left and right subtrees, respectively.
1
• When a left (right) child with 0 children is merged into an operator, replace L (R)
with the value of the child.
• When a node has 1 child, it has an expression that is a function of one variable.
When a left (right) child with 1 child is merged into an operator, replace L (R) with
the expression and change the variable in the expression to L (R) if appropriate.
In a node with 2 children, the operands in the expression are f (L) and g(R), where f
and g are linear functions, and in a node with 1 child, the expression is h(x), where h is
a linear function and x is either L or R. We prove this invariant by induction. At the
beginning, the invariant is clearly satisfied. There are three types of merges that result
in a not fully evaluated expression.
1. A 1-child node is merged into a 2-children node.
2. A leaf is merged into a 2-children node.
3. A 1-child node is merged into a 1-child node.
All three types of merges do not change the invariant. Therefore, every merge simply
evaluates or composes linear functions, which takes constant time.
3
More Applications
This section is a brief overview. More details will be given in class.
• When given a binary tree, we can compute the height of every node by using parallel
tree contraction to evaluate max(L + 1, R + 1) for every node.
• When given two binary trees, we can determine (with high probability) whether
they are isomorphic by using the following procedure.
1. Compute the height of every node.
2. Conceptually, we assign every node a polynomial in x1 , . . . , xh , where h is the
height of the root.
– Every leaf is assigned x1 .
Q
– Every other node is assigned children v (xi − p(v)), where i is the height of
the node and p(v) is the polynomial assigned to node v.
3. Algorithmically, we evaluate (xi − L)(xi − R), where xi is chosen randomly
from a sufficiently large field.
4. If the expressions in the root nodes evaluate to the same value, return “isomorphic”. Otherwise, return “not isomorphic”.
2