CSCI 4041 HW#3 Solution Key (Fall 2009)
1.
[30pt]
a.
[15pt] Successive calls to TreeSuccessor constitute a partial traversal of the tree,
starting at node x and continuing for next k nodes. The successive calls will involve
O(k+h) nodes, which implies a total of O(k+h) distinct edges will be traversed because it
is tree. However, each such edge will be traversed at most twice: once going down and
once coming up. The complexity of the algorithm is of the order of the number of edge
traversals. The partial traversal which is done by k successive calls to TreeSuccessor will
visit at least k nodes (the k successors of x).
Assuming we start at node x. Let y be the
k^th successor of x, i.e., the last node obtained in the k successive calls. The traversal
may visit some number of additional nodes with keys <= key(x) and keys >= key(y).
In
the worst case, node x is a leaf at maximum depth h whose successor corresponds to
the root.
The number of nodes visited with keys <= key(x) is h2.
So, the number of
nodes visited is at most k+h2, and the running time is O(k+h). Similarly, since y is the
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 karypis
 Dynamic Programming, Standing wave, successive calls

Click to edit the document details