What is the height of the binary search tree obtained by inserting the numbers 40, 60, 50, 37, 52, 15, 8, 22 in the given order
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. 3
Explanation
Inserting in order builds the BST as follows: 40 becomes the root; 60 goes to 40's right; 50 (less than 60) goes to 60's left; 37 (less than 40) goes to 40's left; 52 (between 50 and 60) goes to 50's right; 15 (less than 37) goes to 37's left; 8 (less than 15) goes to 15's left; and 22 (between 15 and 37) goes to 15's right. The longest root-to-leaf paths, 40→37→15→8, 40→37→15→22 and 40→60→50→52, each contain 3 edges. Counting height as the number of edges on the longest root-to-leaf path, the height of this BST is 3.More Data Structures and Algorithms questions
- Match the LIST-I with LIST-II. LIST-I (Data structure) LIST-II (Characteristics) A. Stack I. First-In-First-Out (FIFO) order B. Queue II. L…
- How will the following min-heap appear on inserting the key 32? Original min-heap (level order): 5, 10, 25, 30, 40, 50, 60, 70, 80, 90 (roo…
- Consider the infix expression Q : ((A + B) ∗ D) ↑ (E − F). The equivalent postfix expression of Q is
- Which of the following trees are height balanced? A. Binary Search Tree B. AVL Tree C. Red-Black Tree D. B Tree Choose the correct answer f…
- Which of the following algorithms use the Greedy strategy? A. Dijkstra's algorithm B. Kruskal's algorithm C. Huffman coding D. Bellman-Ford…
- The longest common subsequence of {1,2,3,2,4,1,2} and {2,4,3,1,2,1} is