Data Structures & AlgorithmsHardGATE CSE · Trees
Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 25 are inserted into an empty BST in this order. The node 30 is then deleted, being replaced by its inorder successor. What is the level-order traversal of the tree afterwards?
- A. 50 25 70 20 40 60 80 35 45
- B. 50 40 70 20 45 60 80 25 35
- C. 50 35 70 20 40 60 80 25 45
- D. 50 20 70 25 40 60 80 35 45
Correct answer: C. 50 35 70 20 40 60 80 25 45
The inorder successor of 30 is 35 (the leftmost node of its right subtree); 35 replaces 30 and its old leaf is removed.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A complete binary tree with 53 nodes is stored in a 1-indexed array (children of i are 2i and 2i+1). How many descendants does the node at…
- A weighted directed graph has edges S->A 6, S->B 7, A->B 8, A->C 5, A->D -4, B->C -3, B->D 9, C->A -2, D->S 2, D->C 7 (it has no negative…
- In a flow network with capacities S->A 10, S->B 8, A->B 5, A->C 7, B->D 10, C->D 4, C->T 9, D->T 10, what is the maximum flow from S to T?
- A directed graph has edges 1->2, 2->3, 2->5, 3->1, 3->4, 4->8, 5->6, 6->5, 6->7, 7->8, 8->4, 9->7, 9->8. How many strongly connected…
- A max-heap is built from the ascending array 1, 2, ..., 15 in two ways: (a) inserting the elements one at a time with sift-up, (b) the…
- A DAG has edges A->B, A->C, B->D, C->D, E->C and F->E (six vertices). How many distinct topological orderings does it have?