GATE Computer ScienceHardGATE CS (PYQ pattern)
Ten people numbered 1 to 10 stand in a circle (a circular linked list in increasing order). Counting starts at person s, who is counted as 1; every 3rd person still present is removed, and counting resumes at the next person, until one person remains. With s = 1 the survivor is person 4. For which starting person s does person 1 survive?
- A. 9
- B. 7
- C. 4
- D. 8
Correct answer: D. 8
Starting the count one place later rotates the whole elimination pattern one place forward, so the survivor for start s is ((4 - 1) + (s - 1)) mod 10 + 1. Setting this equal to 1 needs (s + 2) mod 10 = 0, i.e. s = 8; a direct simulation from s = 8 confirms that person 1 is left.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A singly linked list has 17 nodes numbered 0 to 16 from the head; node 16 points back to node 7 (so the tail of length 7 leads into a…
- A routine rev(k) reverses every block of k consecutive nodes of a singly linked list in place, leaving a final block of fewer than k nodes…
- A queue is built from two stacks: enqueue pushes onto stack IN; dequeue pops from OUT, and if OUT is empty it first moves every element of…
- A BST is built by inserting 50, 30, 70, 20, 40, 60, 80 in some order into an initially empty tree. The final tree is the perfectly…
- Insert 45, 25, 65, 15, 35, 55, 75, 10, 20, 30, 40, 50, 60 into an empty BST. Then delete 25, 45 and 65 in that order, replacing a node…
- A full binary tree (every node has 0 or 2 children) has preorder 1 2 4 5 8 9 3 6 10 11 7 and postorder 4 8 9 5 2 10 11 6 7 3 1. What are…