Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
A binary trie of 6-bit numbers stores the set S = [63, 33, 9, 22, 26, 2, 29]. For the query x = 24, what is the maximum value of x XOR s over all s in S? (Answer as a decimal integer.)
- A. 2
- B. 39
- C. 57
- D. 24
Correct answer: C. 57
A greedy walk down the trie that prefers the opposite bit at every level finds the maximum 57. 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
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–G, B–E, B–H, D–E, D–F, D–G, D–H. What is the size of a…
- Connected undirected graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–F (1), B–F (1), B–G (1), C–F (1), D–F (1), E–F (1), F–G…
- Array A = [3, 8, 11, 5, 4, 7, 7]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Directed weighted graph on vertices B, E, C, F, A (source B, target A) with edges: B→E (2); B→C (6); C→E (-5); E→A (3); C→A (4); B→A (8)…
- Strings a = "acbc" and b = "aabc". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Keys [30, 27, 11, 18, 49, 38, 37] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…