Data Structures & AlgorithmsModerateInfosys · Trees
A complete binary tree stored level by level has exactly 40 nodes. How many of them are leaves?
- A. 20
- B. 19
- C. 21
- D. 18
Correct answer: A. 20
The last internal node is at index floor(40/2) = 20, so nodes 21 to 40 are leaves: 20 of them.
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
- Keys 14, 8, 11, 5, 9, 3, 12 are inserted one at a time into an initially empty binary min-heap kept in an array. What does the array hold…
- An undirected graph has edges A-B, A-C, B-D, B-E, C-E, C-F, D-G, E-G, F-G. Neighbours are always visited in alphabetical order. What is…
- A binary tree has inorder traversal D B E A F C and postorder traversal D E B F C A. What is its preorder traversal?
- How many structurally different binary search trees can be built from 5 distinct keys?
- A DAG has edges A->C, A->D, B->D, C->E, D->E, D->F, E->G, F->G. Using Kahn's algorithm and always removing the alphabetically smallest…
- In the directed graph with edges S->A (4), S->B (1), B->A (2), A->C (5), B->C (8), B->D (10), C->D (2), C->T (6), D->T (3), what is the…