GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A singly linked list has 25 nodes. A routine places pointer p at the head and pointer q at the 6th node from the head, then advances both one step at a time until q->next == NULL. Which node (counted from the head, 1-indexed) does p point to at the end, and how many nodes have been visited by q in all, counting its initial position?
- A. node 19, 20 visited
- B. node 20, 19 visited
- C. node 20, 20 visited
- D. node 21, 25 visited
Correct answer: C. node 20, 20 visited
q starts at node 6 and stops at node 25 (q->next == NULL): 19 advances, so p reaches node 1 + 19 = 20. q visits nodes 6 to 25 = 20 nodes counting its start.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 12-bit sets are stored as bit vectors: A = 101101101101, B = 011010110011, C = 111000011010 (most significant bit first). What are the…
- int f(int a[], int l, int r) { if (l == r) return a[l]; int m = (l + r) / 2; int x = f(a, l, m), y = f(a, m + 1, r); return x > y ? x : y…
- Keys 50, 30, 70, 20, 40, 60, 80, 10, 35, 45, 65, 85, 5, 15, 32, 38, 90 are inserted in this order into an empty BST (root at depth 0)…
- A min-heap is built from [27, 5, 19, 3, 41, 8, 16, 2, 33, 11, 24, 7] by bottom-up heapify, and then extract-min (last element to the root…
- int m[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; for (int i = 0; i < 4; i++) for (int j = 0; j < i; j++) {…
- A routine reverses the entire string in place and then reverses each maximal run of non-space characters in place. It is applied twice in…