0% found this document useful (0 votes)
5 views2 pages

4101 Assignment 5

The document outlines the process for efficiently rebuilding an External Binary Search Tree (BST) for delete and find operations, focusing on in-order traversal and constructing a balanced BST. It discusses the decision to rebuild the tree when half of the leaves are marked as deleted, ensuring amortized costs for delete operations remain O(1). Additionally, it details the worst-case time for find operations, which is O(log n) due to the tree's balanced nature.

Uploaded by

rajpunjabi47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

4101 Assignment 5

The document outlines the process for efficiently rebuilding an External Binary Search Tree (BST) for delete and find operations, focusing on in-order traversal and constructing a balanced BST. It discusses the decision to rebuild the tree when half of the leaves are marked as deleted, ensuring amortized costs for delete operations remain O(1). Additionally, it details the worst-case time for find operations, which is O(log n) due to the tree's balanced nature.

Uploaded by

rajpunjabi47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

York University EECS 4101/5101

Homework Assignment #6

October 22, 2024

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.

2. Constructing a New Balanced BST:


• After collecting the unmarked keys during the traversal, we have a sorted list of keys.
• Using this sorted list, we can build a new balanced BST in Θ(n) time. This process ensures that
the tree remains perfectly balanced, maintaining a height of ⌈log2 m⌉, where m is the number of
unmarked leaves.

Total Rebuild Time: Each step (traversal and reconstruction) takes Θ(n), thus the overall time
complexity for rebuilding the tree is:
Θ(n)

(b) Deciding When to Rebuild the Tree


To achieve the desired time bounds, we decide to rebuild the tree when the number of marked nodes reaches
n
2 (i.e., half of the leaves are marked as deleted).
This threshold allows us to amortize the cost of each rebuild over the preceding deletions, ensuring that
the cost remains manageable and the amortized time per Delete stays O(1).

(c) Amortized Time per Delete Operation


Using the potential method, we define the potential function:

Φ=m

where m is the number of marked (deleted) leaves in the tree.

1. Actual Cost of Delete:

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

3. Amortized Cost Calculation:

• The amortized cost of the Delete operation is given by:

A = C + ∆Φ = O(1) + 1 = O(1)

Thus, the amortized cost per Delete operation is O(1).

Analysis of Rebuild Operation


n
When the number of marked leaves reaches 2, we perform a rebuild:

1. Actual Cost of Rebuild:

• 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)

3. Amortized Cost of Rebuild:

• Now we can compute the amortized cost of the rebuild operation:

Arebuild = Crebuild + ∆Φ = Θ(n) − Θ(n) = O(1)

• 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.

(d) Worst-Case Time per Find Operation


Since we rebuild the tree to be perfectly balanced whenever the number of marked leaves reaches n2 , the
height of the tree is maintained at O(log n), where n is the number of active (unmarked) nodes.
A Find operation traverses from the root to a leaf. In the worst case, the time taken to perform this
operation in a balanced BST is:
O(log n)
Therefore, the worst-case time for a Find operation is O(log n).

You might also like