GATE Computer ScienceVery hardGATE CS
A singly linked list has a tail of 6 nodes leading into a cycle of 9 nodes. A pointer 'slow' moves 1 node per step and a pointer 'fast' moves 3 nodes per step, both starting at the head. After how many steps do the two pointers first point to the same node?
- A. 6
- B. 9
- C. 12
- D. 15
Correct answer: B. 9
Both are in the cycle once slow has taken at least 6 steps. Inside the cycle the gap grows by 2 per step, so they meet when 2t ≡ 0 (mod 9) and t ≥ 6, i.e. when t is a multiple of 9. The first such t is 9.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- An open-addressing table of size 11 uses h(k) = k mod 11 with linear probing and tombstones. Insertion places the key in the first empty…
- A sparse table for range-minimum queries on an array of 1000 elements stores, for each level k = 0, 1, ..., ⌊log₂ 1000⌋, one entry for…
- A segment tree over positions 0 to 12 (13 elements) is built recursively: the root is node 1, the node for [lo, hi] splits at mid = (lo +…
- A B-tree with minimum degree t = 3 (every node except the root has between 2 and 5 keys) is built with the CLRS insertion procedure, which…
- Items 1, 2, 3, 4, 5 arrive in this order and are inserted, each at either the front or the back of a double-ended queue (the choice is…
- A tree has 16 nodes numbered 0 to 15 with the parent array parent[1..15] = 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 9, 9, 10 (node i has parent…