GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A queue is a circular array that starts with capacity 4 and doubles (copying every element) when an enqueue finds it full; dequeues never shrink it. The operations are E E E E E D E E E D D E E E E E E E E E D E E E E E E E E (E = enqueue, D = dequeue). How many element copies are made in total, and what is the final capacity?
- A. 24 copies, capacity 32
- B. 28 copies, capacity 64
- C. 28 copies, capacity 32
- D. 36 copies, capacity 16
Correct answer: C. 28 copies, capacity 32
Doubling occurs whenever an enqueue finds the live size equal to the capacity. Tracing the live size through the operations triggers copies at the sizes found in the trace, totalling 28; the final capacity is 32.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- unsigned char x = 0x5B; unsigned s = 0; for (int i = 0; i < 6; i++) { x ^= (unsigned char)(x << 3); x ^= x >> 2; s += x; } printf("%u %u"…
- A bracket checker pushes every opening bracket and, on a closing bracket, pops and compares. For the string {[()()]([{}])}[({[]}) the…
- A queue holds 5, 12, 7, 3, 9, 14, 2, 8 (front first). To reverse the first 5 elements, they are dequeued onto a stack, popped back and…
- In the binary tree (key, left, right) = (44, (20, (12), (8)), (24, (9, (4), (5)), (15, -, (15)))), how many non-leaf nodes have a key…
- int ds(int n) { return n < 10 ? n : ds(n / 10) + n % 10; } int steps(int n) { int c = 0; while (n >= 10) { n = ds(n); c++; } return c; }…
- The keys 3, 9, 6, 12, 1, 15, 8 are inserted one after another into an initially empty max-heap (each insertion places the key at the end…