Data Structures & AlgorithmsHardTCS NQT · Infosys pattern
A circular queue in an array of size 6 uses front (index of the first item) and rear (index of the next free slot), both starting at 0, with one slot kept empty. After enqueuing a, b, c, d, e, dequeuing twice, then enqueuing f and g, what are rear and the queue state?
- A. rear = 1 and the queue is full
- B. rear = 0 and the queue is full
- C. rear = 7 and the queue is full
- D. rear = 1 and one more item can be added
Correct answer: A. rear = 1 and the queue is full
After 5 enqueues rear = 5; two dequeues make front = 2; f goes to 5 (rear wraps to 0) and g to 0 (rear = 1). Now (rear + 1) mod 6 = 2 = front, so with one slot reserved the queue is full with 5 items. rear = 7 forgets the wrap-around.
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
- A 2-D array A[10][20] (indices from 0) of 4-byte integers is stored in COLUMN-major order starting at address 1000. What is the address of…
- Only the lower triangle (including the diagonal) of a 10 × 10 matrix is stored, row by row, in a 1-D array starting at address 2000, with…
- What is printed? (Python) python a = [3, 8, 1, 9, 4] a.insert(2, 7) a.pop() a.remove(9) print(a, len(a))
- A circular queue of size N = 5 keeps one slot empty. What is printed (dequeued values, 'F' for each rejected enqueue, final count)? c…
- Keys 50, 700, 76, 85, 92, 73, 101 are inserted into a hash table of size 7 with h(k) = k mod 7 and linear probing. What is the final table…
- Keys 22, 33, 44, 55 go into a table of size 11 with quadratic probing h(k) + i² (mod 11). In which slots do they land, in order? python m…