Stacks and Queues Flashcards

1
Q

Name 3 places where stacks are directly applied and why they are suitable for these tasks

A
  1. 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
  2. History in browser, the last page you visited will be the first one the is accessible.
  3. A chain of methods in the JVM
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name 3 direct applications of queues

A
  1. shared resources
  2. waiting lists
  3. multiprogramming (a computer running 2 or more opertation/ programs at the same time)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

performance and limitation of the array based queue

A
  • enqueue is O(1) and dequeue is O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly