Question

1.Write in pseudocode a recursive algorithm for the operation deleteHighest (t), where t is the root...

1.Write in pseudocode a recursive algorithm for the operation deleteHighest (t), where t is the root of the BST, to delete the largest element in a BST

2.Fill in the following table, giving the “worstcase”time complexity for each operation, ineach of the two implementations, assumingthe PQ contains n elements.

insert deleteHighest
Worst case time compexity
Heap
BST

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part-1 Binary search tree has maximum values at right side of root and also largest value can be possible in two positions-

first is right most child node of tree. in this case, we can delete directly that node.

second case is when tree has largest element on level from bottom. In this case largest node would have a left child which is smaller than largest element of tree. in this case we have to replace largest element with its left child.

Now lets see the pseudo code-

deleteHighest(t)

{

put value of root in a key

//define a function, say delKey(key)

if right side of key is null

delete node and check if left node is not null

then replace with left node

otherwise free(key);

//function delKey() over here

if right side is present

put value of root in max;

compare and traverse till largest element

put value of maximum in key;

call delKey(key)

}

Part two-

Worst case complexity will be O(n) in both insertion and deletion. Because worst case can be at last most node of tree. So n will be height/levels available in tree.

Add a comment
Know the answer?
Add Answer to:
1.Write in pseudocode a recursive algorithm for the operation deleteHighest (t), where t is the root...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT