Data Structures & AlgorithmsEasyWipro · Accenture pattern
Keys 50, 30, 70, 20, 40, 60, 80 are inserted in that order into an empty BST. How many leaves does the tree have, and what is its height (edges on the longest root-to-leaf path)?
- A. 4 leaves, height 3
- B. 7 leaves, height 2
- C. 3 leaves, height 2
- D. 4 leaves, height 2
Correct answer: D. 4 leaves, height 2
50 is the root with children 30 and 70, which get 20, 40 and 60, 80 as children: a perfect tree with 4 leaves and height 2 in edges. Height 3 counts levels (nodes) instead of edges.
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
- What is the maximum number of nodes in a binary tree of height 4, where a single-node tree has height 0?
- What is the minimum possible height of a binary tree with 100 nodes (height of a single node = 0)?
- With the edges sorted first, what is the time complexity of Kruskal's algorithm using a union-find structure, for a graph with V vertices…
- Which single-source shortest path algorithm can detect a negative-weight cycle reachable from the source?
- A topological ordering of a directed graph exists if and only if the graph is:
- A heap is stored in a 0-indexed array. What is the index of the parent of the element at index 10, and of its left child?