Data Structures & AlgorithmsHardICPC regional · GATE CS top band
A binary trie of 6-bit numbers stores the set S = [52, 29, 43, 11]. For the query x = 29, what is the maximum value of x XOR s over all s in S? (Answer as a decimal integer.)
- A. 54
- B. 41
- C. 0
- D. 29
Correct answer: A. 54
A greedy walk down the trie that prefers the opposite bit at every level finds the maximum 54. Only checking the largest stored element, or picking the smallest XOR, are the usual slips.
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 weighted edges A–B (6), A–G (9), B–C (6), B–G (8), C–D (6), C–F (1), D–G (8), E–F…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–G (1), B–E (1), C–D (1), C–F (1), C–G (1), D–E (1), D–F (1)…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–C (1), A–D (1), A–E (1), B–C (1), B–E (2), D–E (3). An edge is…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: B→E (7); E→A (6); B→D (3); B→C (3); B→A (4); A→B…
- Array A = [5, 20, 23, 4, 3, 30, 2, 24]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 19? (A trie with subtree counts answers this…
- Distinct words ['ccc', 'aaa', 'cb', 'bbbc', 'ba', 'ca', 'bb'] are inserted into an empty trie (one node per character, shared prefixes…