GATE Computer ScienceModerateGATE CS (PYQ pattern)
A singly linked list 1 -> 2 -> ... -> 12 is modified by reversing the sublist from position 3 to position 9 (1-indexed, inclusive), and then reversing the sublist from position 5 to position 11 of the resulting list. What is the list now?
- A. 1 2 11 10 9 8 7 6 5 4 3 12
- B. 1 2 7 8 9 10 11 4 3 6 5 12
- C. 1 2 9 8 11 10 3 4 5 6 7 12
- D. 1 2 9 8 7 6 5 4 3 10 11 12
Correct answer: C. 1 2 9 8 11 10 3 4 5 6 7 12
After the first reversal the list is 1 2 9 8 7 6 5 4 3 10 11 12; reversing positions 5 to 11 of that gives 1 2 9 8 11 10 3 4 5 6 7 12.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Eight sorted lists of 100 keys each (800 distinct keys) are merged with the standard two-way merge, whose worst case for lists of sizes p…
- The number of nodes of a complete binary tree is found recursively: compute the leftmost-path height and the rightmost-path height of the…
- A BST is built from the sorted array 1, 2, ..., 14 by recursion: the root is a[mid] with mid = (lo + hi) / 2 (integer division), then the…
- In a binary tree given as (key, left, right) = (10, (-20, (8), (-6, (4), -)), (15, (-3), (12, (7), (-9)))), a 'path' is any sequence of…
- An AVL tree is built by inserting 1, 2, ..., 15 in increasing order (the perfect tree with root 8). Then keys 1, 3, 5, 2, 4 are deleted in…
- Cuckoo hashing uses two tables of size 7: h1(k) = k mod 7 in T1 and h2(k) = floor(k / 7) mod 7 in T2. To insert x, place it in T1[h1(x)]…