Stacks and Queues Flashcards

1
Q

stack basics

A

last in first out

aka push down stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

stack operations

A

push - append element to stack
pop - get recent element and delete from stack
top - get recent element but does not delete
is_empty - if True, stack has no elements
get_size - returns the count of elements in the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

stack exception cases

A

underflow - pop or top attempted on an empty stack

overflow - when push is attempted but stack has taken up all allotted space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to declare an empty stack

A

my_stack = []

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

queue basics

A

controls flow of tasks
first in first out
enqueue, dequeue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

queue operations

A

enqueue - appends element to queue
dequeue - fetches the value from the least recent element and removes it
front - fetches the value of the least recent element enqueued and removes it
is_empty
get_size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

queue rules

A
  1. appending and removing need to happen at opposite end of the list being used to act like a queue
  2. avoid queues.py
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

priority queues

A
  • add in a new element and its priority
  • every element has a priority
  • can be a fixed size
  • if there is another element added w/ the same priority, then the most recently added one will go first
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

application of stacks and queues

A

stacks evaluate prefix, postfix and infix expressions

queues - job queuing, buffering keyboard input

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

enqueue

A

appends element to queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

dequeue

A

returns the value of least recent element and removes it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

front

A

fetches the value of the least recent element enqueued but doesn’t remove it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

is_empty

A

if True, queue/stack has no elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

get_size

A

returns the count of elements on the queue/stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

push

A

appends element to stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

pop

A

returns value of most recent element in stack and deletes it

17
Q

top

A

returns value of most recent element in stack but doesn’t delete it