Data Structures & AlgorithmsHardGATE CS · ICPC regional
A binary trie of 6-bit numbers stores the set S = [39, 63, 46, 44, 8]. 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. 58
- B. 29
- C. 34
- D. 21
Correct answer: A. 58
A greedy walk down the trie that prefers the opposite bit at every level finds the maximum 58. 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
- Complete undirected graph on vertices A to E with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(12) and count every invocation of f…
- Coins of denominations [9, 8, 7, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 22?…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→C (9)…
- Connected undirected weighted graph on vertices A, B, C, D with edges A–B (6), A–D (5), B–C (3), B–D (4), C–D (4). Among all spanning…
- Directed acyclic graph on vertices A, B, C, D, E, F with edges A→F, A→C, A→E, F→D, B→E, D→C. Among all topological orderings (every edge…