GATE Computer ScienceModerateGATE CS (PYQ pattern)
A singly linked list 1 -> 2 -> ... -> 20 undergoes two passes: first every 3rd node (by current position) is deleted, then in the resulting list every 4th node (by current position) is deleted. What is the sum of the remaining nodes?
- A. 126
- B. 104
- C. 147
- D. 114
Correct answer: D. 114
After deleting positions 3, 6, ..., 18 the list is [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20]; deleting every 4th of those removes [5, 11, 17]; the remaining sum is 114.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int x = 1; int inc(void) { return x += 1; } int dbl(void) { return x = 2; } int sq(void) { return x = x; } int (fp[3])(void) = {inc, dbl…
- A table of size 13 uses double hashing, probe i of key k is (k mod 13 + i (1 + k mod 11)) mod 13. Keys 18, 41, 22, 44, 59, 32, 31, 73 are…
- A BST on 31 keys is perfectly balanced (all 5 levels full). Searching for each of the 31 keys with equal probability, what is the average…
- Keys 1 to 5 are inserted into an empty BST in a uniformly random order of the 120 possible orders. In how many of the orders does key 3…
- Iterative postorder uses two stacks: push the root on S1; repeat: pop x from S1, push x on S2, push x's left child then its right child on…
- struct N { int v; int next; }; struct N a[6] = {{10,3},{20,5},{30,-1},{40,1},{50,2},{60,4}}; int i = 0, s = 0, k = 1; while (i != -1) { s…