Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array A = [20, 5, 12, 11, 18, 29, 30, 31, 17]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 9? (A trie with subtree counts answers this in O(n·bits); the answer here is a plain integer.)
- A. 15
- B. 9
- C. 7
- D. 29
Correct answer: C. 7
Walking the trie with subtree counts, only pairs whose XOR is strictly below 9 are added, giving 7. Including equality or swapping to '>' are the mistakes that produce the other options.
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
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–B (1), B–C (1), B–D (1), B–F (1), B–G (1), C–D (1), C–F (1), D–G (1), E–F…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (5), A–D (2), B–C (6), C–D (3), C–E (1), D–E (1). Among all…
- Keys are inserted in the order 88 50 42 89 48 68 into an empty binary search tree. Then the key 88 (which has two children) is deleted by…
- A binary tree with distinct letters has preorder DEFACB and inorder FAECDB. What is its postorder traversal (left, right, root), written…
- Dictionary D = {ada, ats, emd, lsc, pcd, pmd, pmo, pno, pnr, rbs, sbp, ssr} (all words have 3 letters). Starting from the word 'ptd', a…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…