GATE Computer ScienceHardGATE CSE · ISRO
A singly linked list holds 1, 2, …, 11 in order. Step 1: reverse it in consecutive groups of 4 nodes (a final group with fewer than 4 nodes is left as it is). Step 2: delete every node whose value is a multiple of 3. Step 3: reverse the whole list. What is the 5th value from the head of the final list?
- A. 7
- B. 8
- C. 1
- D. 5
Correct answer: B. 8
After step 1: 4 3 2 1 8 7 6 5 9 10 11; after step 2 and the full reversal the list is 11 10 5 7 8 1 2 4, whose 5th value is 8.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Infix a+bc^d^e-(f+g)h/i^j^k is converted to postfix with the usual stack algorithm: operators and "(" are pushed on a stack, an operator…
- A binary tree on keys 1 to 6 has preorder 1 2 3 4 5 6 and postorder 3 2 6 5 4 1. Treating a left child and a right child as different, how…
- An array int A[-2..3][4..9][1..5] (inclusive bounds, 4-byte ints) is stored in row-major order starting at byte address 1000. What is the…
- The non-zero elements of a 30 × 30 tridiagonal matrix (non-zeros only where |i − j| ≤ 1, indices 1-based) are stored row by row in a 1-D…
- A circular queue uses an array of size 8 with indices 0–7. Initially front = rear = 0. Enqueue: if (rear+1) mod 8 == front the queue is…
- A directed graph on vertices 1–8 has adjacency lists 1:[2,5]; 2:[3,6]; 3:[4,1]; 4:[2,7]; 5:[6,4]; 6:[7]; 7:[5,8]; 8:[3,6]. DFS starts at…