Stacks and Queues Flashcards
1
Q
Name 3 places where stacks are directly applied and why they are suitable for these tasks
A
- Undoing in a text editor. Because the last change is the one you’d mostly want to disappear the stack works efficiently in popping the last change you made
- History in browser, the last page you visited will be the first one the is accessible.
- A chain of methods in the JVM
2
Q
How does recursion happen with the JVM?
A
- JVM keeps track of all the active methods by pushing in a frame containing the local variables and the return values in the stack. The program counter will keep track of the statement being executed.
- WHen a method is finished, it’s frame will be popped off the stack and control goes to the method that is at the top of the list.
3
Q
What is the performance and limitation of the array based stack
A
- space is O(N), with N being the size of the array
- Operations run at O(1)
- limitations is that the size of the stack has to be determined before, it is not dynamic
4
Q
Name 3 direct applications of queues
A
- shared resources
- waiting lists
- multiprogramming (a computer running 2 or more opertation/ programs at the same time)
5
Q
performance and limitation of the array based queue
A
- enqueue is O(1) and dequeue is O(1)