GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The Tower of Hanoi with 6 disks is played on three pegs in a row (left, middle, right), and a disk may move only between adjacent pegs. What is the minimum number of moves to transfer all disks from the LEFT peg to the MIDDLE peg?
- A. 728
- B. 364
- C. 63
- D. 365
Correct answer: B. 364
Moving the stack left→middle: shift the top 5 disks left→right (adjacent-only, 3⁵ − 1 = 242 moves), the big disk left→middle (1), then the 5 disks right→middle (A(5)). So A(n) = 3^(n−1) + A(n−1), A(1) = 1, giving A(n) = (3ⁿ − 1)/2 = 364. 728 = 3⁶ − 1 is the left→right count; a BFS over all 3⁶ states confirms 364.
More Algorithms questions
- Of the 92 solutions of the 8-queens problem (rotations and reflections counted separately), how many have no queen on either of the two…
- Four men m0–m3 and four women w0–w3 have preference lists (best first) m0: w1 w0 w2 w3; m1: w0 w2 w1 w3; m2: w1 w3 w2 w0; m3: w0 w1 w3 w2…
- For n = 5 distinct keys, let M be the worst-case comparisons of top-down merge sort (split ⌈n/2⌉ + ⌊n/2⌋, merge stops when one side is…
- What is the minimum number of comparisons that guarantees finding the median (the third smallest) of 5 distinct elements in the worst case?
- A hash table with chaining has m = 50 slots and stores n = 200 keys; each key is equally likely to be in any slot (simple uniform…
- Twenty distinct keys are hashed independently and uniformly into 100 slots. What is the expected number of keys that share their slot with…