GATE Computer ScienceVery hardGATE CSE
A binary tree on keys 1 to 6 has preorder 1 2 3 4 5 6 and postorder 3 2 6 5 4 1. Treating a left child and a right child as different, how many distinct binary trees have exactly these two traversals?
- A. 8
- B. 16
- C. 7
- D. 1
Correct answer: A. 8
A node with a single child can have it on either side; 1 has left subtree {2,3} and right subtree {4,5,6}; 2 has one child (2 ways), and in the chain 4–5–6 each of 4 and 5 has one child (2 ways each), so 2·4 = 8 trees.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- An array int A[-2..3][4..9][1..5] (inclusive bounds, 4-byte ints) is stored in row-major order starting at byte address 1000. What is the…
- The non-zero elements of a 30 × 30 tridiagonal matrix (non-zeros only where |i − j| ≤ 1, indices 1-based) are stored row by row in a 1-D…
- A circular queue uses an array of size 8 with indices 0–7. Initially front = rear = 0. Enqueue: if (rear+1) mod 8 == front the queue is…
- A directed graph on vertices 1–8 has adjacency lists 1:[2,5]; 2:[3,6]; 3:[4,1]; 4:[2,7]; 5:[6,4]; 6:[7]; 7:[5,8]; 8:[3,6]. DFS starts at…
- Strings X = ABCBDABA and Y = BDCABAB are given. How many distinct longest common subsequences (distinct as strings) do they have?
- Words car, card, care, cart, cat, dog, door, dot, dove, do, cargo, carbon, catalog, cat are inserted into an initially empty trie (a…