GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 cycle of length 10). Slow moves 1 step and fast moves 2 steps per round, both starting at node 0. After how many rounds do they first meet, and at which node?
- A. 8 rounds at node 10
- B. 10 rounds at node 10
- C. 10 rounds at node 7
- D. 11 rounds at node 11
Correct answer: B. 10 rounds at node 10
They meet after t rounds where The fast pointer gains 1 node per round, so they meet when the gap is a multiple of the cycle length 10 and both are inside the cycle; the first such round is t = 10, where slow stands at node 10 (not at the entry node 7).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- Binary trees (unlabelled, left and right children distinguished) with exactly 6 nodes: how many have height exactly 3 (a single node has…