Data Structures & AlgorithmsHardTCS NQT · Trees
Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65, 85 are inserted into an empty BST in this order. What is the lowest common ancestor of the nodes 35 and 45?
- A. 30
- B. 35
- C. 40
- D. 50
Correct answer: C. 40
Both 35 (left child) and 45 (right child) hang below 40, which is the lowest node having them in different subtrees.
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 words car, card, care, cat, dog, dot, do are inserted into an initially empty trie. How many nodes does the trie contain, not counting…
- A Fenwick (binary indexed) tree over indices 1 to 16 is used. Updating position 5 touches the nodes 5, 6, 8, 16 (add the lowest set bit…
- 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…
- 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?