Data Structures & AlgorithmsHardGATE CSE · Trees
In a binary tree every node has 0 or 2 children, except 7 nodes that have exactly one child, and there are 12 nodes with two children. How many nodes does the tree have in total?
- A. 31
- B. 30
- C. 25
- D. 32
Correct answer: D. 32
Leaves = (nodes with two children) + 1 = 13, so the total is 13 + 7 + 12 = 32.
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
- A depth-first search runs on a directed graph with edges A->B, A->C, B->D, C->E, D->E, D->B, E->F, F->C, G->A, G->F, starting from A and…
- 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…
- 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…