Standard difficulty · 20 questions · 40 marks · Time: 42 minutes
Show your working for Sections B and C. Answers are on the last page — try every question first!
Stack · AW-12CS-STK-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.
| Q | Answer | Working |
|---|---|---|
| 1 | (d) Last In, First Out (LIFO) | — |
| 2 | (a) [86, 89, 83] | the last item pushed is the first popped (LIFO) |
| 3 | (a) 75 | pop() returns the item on top: the one pushed most recently |
| 4 | (b) 119 | stack after each token: [7] [7, 9] [7, 9, 8] [7, 17] [119] |
| 5 | (a) AB+C/D- | operands go straight to the output; an operator waits on the stack until one of lower precedence (or a closing bracket) comes |
| 6 | (d) {{{}}}{{[]}[]}[()] | push each opening bracket; each closing bracket must match the one popped; the stack must end empty |
| 7 | (b) 3 | stack after each token: [2] [2, 8] [2, 8, 9] [2, 17] [2, 17, 5] [2, 85] [170] |
| 8 | (a) 5 | items pushed minus items popped (an Underflow pops nothing) |
| 9 | A linear data structure in which items are added and removed only at one end, the top (LIFO); e.g. a pile of plates. | — |
| 10 | 84, 95, [10, 50, 83] | LIFO: each pop takes the most recent push |
| 11 | 7 | stack after each token: [7] [7, 3] [7, 3, 3] [7, 1] [7] |
| 12 | ABCD-+/ | operands to the output; an operator first pops those of equal or higher precedence |
| 13 | EUEUQ | the characters come off the stack in reverse order |
| 14 | Yes | every closing bracket matches the top of the stack and the stack ends empty |
| 15 | 8, 4 | stacks: [8] [8, 4] [8, 4, 2] [8, 6] [2] [2, 9] [11] |
| 16 | 26 | the top is the last item pushed that was not popped |
| 17 | st = []; push: st.append(x); pop: if st: print(st.pop()) else print("Underflow"); peek: print(st[len(st) − 1]) if st else "Empty"; display: for x in reversed(st): print(x). A while loop shows the menu and calls the chosen function. | — |
| 18 | (a) 51; (b) [43, 69, 73, 63, 46, 32]; (c) 32 | LIFO; pop() on an empty stack returns Underflow |
| 19 | (a) AB/CD/+; (b) 2 | operands go to the output; ( is pushed; ) pops to the matching (; an operator pops those of equal or higher precedence first |
| 20 | (a) 9; (b) the right operand was pushed last, so it comes off first; a − b and a // b need the operands in their original order. | evaluates the postfix expression 3, 6, +, 9, 9, /, / |