GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A priority queue is a sorted singly linked list (ascending). Insert scans from the head, comparing the new key with each node, and stops at the first node whose key is >= the new key (inserting before it), or at the end. Keys 15, 8, 23, 4, 16, 42, 8, 11 are inserted, then three extract-min operations are done. How many key comparisons are made by the insertions in all?
- A. 21
- B. 19
- C. 16
- D. 28
Correct answer: B. 19
Count each node examined: for every insertion this is the number of smaller nodes plus one stopping node (if any). The total is 19; extract-min needs none.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Keys 1..7 form a max-heap stored in a 0-indexed array (children of i are 2i+1, 2i+2). The key 5 is the third largest. In how many…
- A hash table starts with 7 slots, uses linear probing with h(k) = k mod size, and after each insertion, if the load factor exceeds 0.7, it…
- A grid (S start, T target, # blocked, . free) is searched by BFS with 4-directional moves: S.#..... .##.###. ....#... .##.#.#. ...#..#T…
- How many 10-bit unsigned values x (0 to 1023) have no two adjacent 1 bits, where bit 9 and bit 0 also count as adjacent (the bits are…
- unsigned g(unsigned n) { return n ^ (n >> 1); } For which 8-bit n is g(n) == 0xB5? Give n in decimal.
- A routine compresses runs in place: each maximal run of a repeated character c of length L becomes c if L = 1, else c followed by the…