GATE Computer ScienceHardGATE CS (PYQ pattern)
A circular singly linked list holds nodes 1 to 100 in order. Deletion starts with node 1 itself and then removes every second remaining node going round the circle (1, 3, 5, ..., then continuing on the second lap) until one node remains. Which node remains?
- A. 73
- B. 72
- C. 64
- D. 100
Correct answer: B. 72
If the deletions started with node 2 (deleting 2, 4, 6, ...) the survivor would be 2(100 - 64) + 1 = 73. Deleting node 1 first is the same process shifted one place back round the circle (the count effectively starts at node 100), so the survivor is the node just before 73: 72. A simulation agrees.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- struct T { int k; struct T l, r; }; int f(struct T n) { return n ? 1 + max(f(n->l), f(n->r)) : 0; } int g(struct T n) { return n ?…
- Keys 30, 10, 40, 5, 20, 35, 50, 15, 25, 45 are inserted in this order into an empty BST, and then the left and right pointers of every…
- A complete binary tree with 20 nodes is stored in A[1..20] with A[i] = i, the children of i at 2i and 2i + 1. The routine v(i) does: if i…
- int a[4][3] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; int (p)[3] = a; p += 2; int q = p + 1; printf("%d %d %d %d", ((p - 1) + 2), (p)[1]…
- char n[] = {"delhi", "mumbai", "chennai", "kolkata"}; char pp = n; ++pp; printf("%s ", pp + 2); printf("%c ", ++pp); printf("%s ", pp[-1]…
- char src[] = "gate0cse"; char dst[20]; char d = dst, s = src; int n = 0; while ((d++ = s++)) n++; printf("%d %zu %zu", n, sizeof(src)…