Data Structures & AlgorithmsHardGATE CS · Product-company placement
Keys 60, 41, 30, 69, 50, 54, 52, 55, 21 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- A. 54, 41, 30, 21, 50, 52, 60, 55, 69
- B. 60, 41, 30, 21, 50, 54, 52, 55, 69
- C. 50, 30, 21, 41, 60, 54, 52, 55, 69
- D. 21, 41, 30, 52, 55, 54, 69, 60, 50
Correct answer: C. 50, 30, 21, 41, 60, 54, 52, 55, 69
Rebalance at the lowest unbalanced ancestor after each insert; the rotations performed are LL at 60, RL at 41, LL at 41. Treating an LR/RL case as a single rotation leaves a wrong (still unbalanced) shape.
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
- The weighted undirected graph A–B (1), A–C (6), A–E (3), B–D (1), C–D (2), C–E (5), D–E (3) has repeated weights. How many different…
- The words stem, stack, step, star, start are inserted into an empty trie (one node per character, shared prefixes share nodes, plus a…
- What is the maximum flow from S to T in the network with directed capacities A→B (15), A→T (2), B→T (10), C→A (2), C→B (13), C→T (9), S→B…
- Symbols occur with frequencies 18, 23, 24, 28, 34, 35. How many bits does an optimal (Huffman) prefix code need for the whole message, and…
- How many topological orderings does the DAG on vertices A–F with edges A→C, B→D, D→C, E→C, F→A, F→C have?
- A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 2, 6, 12, 16, 17, 19, 21, 23. What is…