4101 Assignment 5
4101 Assignment 5
Homework Assignment #6
1. External Binary Search Tree (BST) for Delete and Find Opera-
tions
(a) Rebuilding the Tree Efficiently
To rebuild the tree efficiently:
1. In-Order Traversal:
• Perform an in-order traversal of the tree to gather all unmarked (undeleted) leaves.
• Since this is a leaf-oriented BST, we only need to focus on the leaves.
• Each node (leaf and internal) is visited once, resulting in a time complexity of Θ(n), where n is
the total number of leaves.
Total Rebuild Time: Each step (traversal and reconstruction) takes Θ(n), thus the overall time
complexity for rebuilding the tree is:
Θ(n)
Φ=m
1
• The Delete operation marks a leaf as deleted, which takes O(1) time.
C = O(1)
2. Change in Potential:
• When a leaf is marked, the number of marked leaves increases by 1:
∆Φ = Φafter − Φbefore = (m + 1) − m = 1
A = C + ∆Φ = O(1) + 1 = O(1)
• The actual cost of rebuilding the tree is Θ(n), as we perform an in-order traversal to collect
unmarked leaves and then construct a new balanced tree from these leaves.
Crebuild = Θ(n)
2. Change in Potential:
• When we rebuild the tree, all marked leaves are reset to unmarked. Hence, m becomes 0 after
the rebuild:
∆Φ = Φafter − Φbefore = 0 − m = −m
n
Since m was at least 2 before the rebuild, we have:
∆Φ = −Θ(n)
• The amortized cost of the rebuild operation is also O(1) when distributed across the n
2 deletions
that led to the need for a rebuild.