Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
A circular queue is implemented in an array of size 7 with front = 4 and rear = 5 (rear indexes the last stored element, the queue is non-empty and wraps around). How many elements does it hold?
- A. 6
- B. 3
- C. 4
- D. 2
Correct answer: D. 2
Count = ((rear − front + n) mod n) + 1 = ((5−4+7) mod 7) + 1 = 2.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Two sorted lists [6, 16, 24, 29] and [20, 22, 25, 35] are merged using the standard merge step. How many element comparisons are made?
- How many swaps does bubble sort (adjacent swaps, ascending) make on [10, 24, 35, 46, 54, 16, 12, 2, 43]?
- A sorted array holds the 19 values 2, 5, 8, … (step 3). Binary search with mid = ⌊(lo+hi)/2⌋ and 0-based indices looks for 20. How many…
- Keys 88, 23, 59, 80, 70, 72, 73, 36 are inserted into a hash table of size 10 with h(k) = k mod 10 and linear probing. At which index is…
- A circular queue is implemented in an array of size 11 with front = 7 and rear = 5 (rear indexes the last stored element, the queue is…
- Quicksort uses the Lomuto partition with the last element as pivot on [32, 15, 43, 18, 25, 39, 6]. After one partition call, at which…