Data Structures & AlgorithmsVery hardGATE CS (PYQ pattern)
Keys 40, 20, 10, 25, 30, 22, 50, 35, 45, 60, 55, 65 are inserted one by one into an initially empty AVL tree. The pre-order traversal of the final tree is:
- A. 40 20 10 25 22 30 35 50 45 60 55 65
- B. 40 25 20 10 22 35 30 50 45 60 55 65
- C. 40 22 20 10 25 35 30 50 45 60 55 65
- D. 40 25 20 10 22 30 35 50 45 60 55 65
Correct answer: D. 40 25 20 10 22 30 35 50 45 60 55 65
Rotations occur on inserting 10 (LL), 30 (LR at 40), 22 (RL at 20), 50 (RR at 30) and 55 (RL at 25), which makes 40 the root with 25 and 50 as children. The first option is the unbalanced plain BST order.
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
- Floyd's bottom-up build-heap (sifting down from the last internal node to the root) is applied to the array [7, 2, 9, 4, 6, 1, 8, 3, 5] to…
- A DAG on vertices 1..6 has edges 1→3, 2→3, 3→4, 3→5, 2→6 and 5→6. How many distinct topological orderings does it have?
- A weighted digraph has edges S→A (2), S→B (5), A→C (4), B→A (−4), B→C (1) and C→T (1). Textbook Dijkstra (a vertex's distance is final…
- An undirected graph on vertices a-f has edges ab(1), bc(2), ac(2), cd(3), bd(3), de(1), ce(4), ae(4), ef(2), df(2). How many distinct…
- A directed graph has the vertices A, B, C, D, E, F, G, H, I and the arcs A→E, B→E, B→F, D→C, E→B, E→C, G→E, G→I, H→B, H→F, I→C, I→H. What…
- An undirected connected graph has the vertices A–J and the edges A–H, B–E, C–I, C–J, D–E, E–G, E–I, F–I, G–J, H–I, H–J, I–J. How many…