QUESTION 05
What is the final peek after the supplied eight operations?
2 marksAnswer
It is 30. The initial bottom-to-top stack is 10, 20, 50, 30, 90, 60; apply the operations in order rather than sorting values.
QUESTION 05
It is 30. The initial bottom-to-top stack is 10, 20, 50, 30, 90, 60; apply the operations in order rather than sorting values.
QUESTION 06
A stack trace updates the logical top after every operation while preserving the untouched bottom portion.
Bottom to top: 10, 20, 50, 30, 90, 60. Capacity is 10 and the initial count is 6. The top is 60.
Bottom to top: 10, 20, 50, 30. Peek is 30 and does not remove it. The count is 4. None of these operations reaches empty or exceeds capacity, so there is no underflow or overflow.
Record the complete remaining sequence or a clear top marker after each step. Distinguish a newly pushed 30 from an earlier equal value if labels help, but the final requested value is still 30. Never remove the bottom item for pop; that would violate LIFO.
For k operations on the bounded array representation, each operation is O(1), so the trace requires O(k) work. This specific trace has a fixed eight operations. Writing every intermediate full stack for display can add output work beyond the stack operations themselves.
The following are topic matches from the supplied papers. Marks are their printed allocations, separate from the practice answer badge.
Starting stack bottom-to-top: 10, 20, 50, 30, 90, 60; capacity 10. Apply pop, push(30), push(40), pop, push(60), pop, pop, pop. Find the final peek value.
Paper DS02 · page 1Starting stack bottom-to-top: 10, 20, 50, 30, 90, 60; capacity 10. Apply pop, push(30), push(40), pop, push(60), pop, pop, pop. Find the final peek value.
Paper DS03 · page 1