After push(1), push(2), push(3), pop(), the top is:
Stacks and Queues
The stack ADT (LIFO) and its array and linked implementations, parentheses and HTML tag matching, evaluating arithmetic expressions with two stacks; the queue ADT (FIFO), circular-array implementation, round robin, and the Big-O of each implementation.
How to read this page
Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.
All 39 slides
- 1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6
- 2 last in first out q
- 3 Stack Interface in Java
- 4 Example
- 5 Slide 5
- 6 Recursion and Queue
- 7 0
- 8 know to
- 9 how match to call
- 10 Performance and Limitations
- 11 Array-based Stack in Java
- 12 Example Use in Java
- 13 Parentheses Matching
- 14 Parenthesis Matching (Java)
- 15 HTML Tag Matching
- 16 HTML Tag Matching (Java)
- 17 Evaluating Arithmetic Expressions
- 18 Algorithm for Evaluating Expressions
- 19 Array Stack Big-oh
- 20 Linked List Stack Big-oh
- 21 Algorithm on an Example Expression
- 22 Presentation for use with the textbook Data Structures and Algorithms in Java, 6
- 23 The Queue ADT
- 24 I
- 25 return
- 26 Applications of Queues
- 27 big
- 28 Queue Operations
- 29 Queue Operations (cont.)
- 30 Queue Operations (cont.)
- 31 Traverse
- 32 Queue Interface in Java
- 33 Array-based Implementation
- 34 Array-based Implementation (2)
- 35 Comparison to java.util.Queue
- 36 Application: Round Robin Schedulers
- 37 Array Queue Big-oh
- 38 DEQueue Big-oh
- 39 LinkedList Queue Big-oh
last in first out q
Exam angle
Performance and Limitations
Notes
Array stack: O(1) operations but fixed capacity.
Parentheses Matching
Notes
Parentheses matching: push openers, pop and compare on closers; stack empty at the end = balanced.
Exam angle
How does a stack check that ( [ { } ] ) is balanced?
Compare with the model answer
Scan left to right: push every opening symbol; on a closing symbol pop and check it matches. If a pop finds the stack empty or a mismatch, it’s unbalanced; at the end the stack must be empty.
The Queue ADT
Exam angle
enqueue(1), enqueue(2), enqueue(3), dequeue() returns:
Array-based Implementation
Exam angle
In a circular array queue of capacity N, the index after r is:
Array Queue Big-oh
Notes
Array queue and linked queue: all operations O(1).