MOD 3_ZYBOOKS 5_STACKS AND QUEUES Flashcards

(21 cards)

1
Q

What is a stack?

A

A stack is an ADT in which items are only inserted on or removed from the top of a stack.

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

What do the stack push and pop operations do?

A

The stack push operation inserts an item on the top of the stack. The stack pop operation removes and returns the item at the top of the stack. Ex: After the operations “Push 7”, “Push 14”, “Push 9”, and “Push 5”, “Pop” returns 5. A second “Pop” returns 9.

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

What does LIFO mean for stacks?

A

A stack is referred to as a last-in first-out ADT.

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

A stack can be implemented using which 3 data stuctures?

A

1) Linked list
2) Array
3) Vector

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

VIEW: Common stack ADT operations.

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

A stack is often implemented using a linked list, with the list’s ____ node being the stack’s top.

A

Head

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

How are stack push and pop operations performed on lists?

A

A push operation is performed by creating a new list node, assigning the node’s data with the item, and prepending the node to the list.

A pop operation is performed by assigning a local variable with the head node’s data, removing the head node from the list, and then returning the local variable.

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

VIEW: Stack push and pop implementation.

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

What is a queue?

What do the enqueue and dequeue operations do?

A

A queue is an ADT in which items are inserted at the end of the queue and removed from the front of the queue.

The queue enqueue operation inserts an item at the end of the queue.
The queue dequeue operation removes and returns the item at the front of the queue.

Ex: After the operations “Enqueue 7”, “Enqueue 14”, and “Enqueue 9”, “Dequeue” returns 7. A second “Dequeue” returns 14.

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

What does FIFO mean in terms of queues?

A

A queue is referred to as a first-in first-out ADT.

A queue ADT is similar to waiting in line at the grocery store. A person enters at the end of the line and exits at the front. British English actually uses the word “queue” in everyday vernacular where American English uses the word “line”.

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

A queue can be implemented using which 2 data structures?

A

1) Linked list
2) Array

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

VIEW: Some common operations for a queue ADT.

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

A queue is often implemented using a linked list, with the list’s ____ node representing the queue’s front, and the list’s ____ node representing the queue’s end.

A

Head, tail

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

For queues, how are enqueueing and dequeueing performed on lists?

A

Enqueueing an item is performed by creating a new list node, assigning the node’s data with the item, and appending the node to the list.

Dequeuing is performed by assigning a local variable with the head node’s data, removing the head node from the list, and returning the local variable.

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

VIEW: Stack.h: Stack implementation using the LinkedList() class.

A

A stack can be implemented in C++ using a class with a single LinkedList data member. The Stack class has two functions, Push() and Pop(). Push() adds a node to the top of the stack’s list by calling LinkedList’s Prepend() function. Pop() removes the head of the stack’s list by calling the LinkedList’s RemoveAfter() function and then returns the removed node’s data. The GetHeadData() function is added to the LinkedList class so that the Stack class’s Pop() function can get the head node’s data before removing the node.

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

VIEW: Demo: Stack implementation using the LinkedList() class.

17
Q

VIEW: Queue.h: Queue implementation using the LinkedList() class.

A

A queue can also be implemented in C++ using a class with a single LinkedList data member and class functions Enqueue() and Dequeue(). Enqueue() adds a node to the end of the queue’s list by calling LinkedList’s Append() function. The Dequeue() function removes the queue’s head node by calling LinkedList’s RemoveAfter() function.

18
Q

VIEW: Demo: Queue implementation using the LinkedList() class.

19
Q

What is a deque?

What do the push-front and push-back operations do?

What do the pop-front and pop-back operations do?

A

A deque (double-ended queue) is an ADT in which items can be inserted and removed at both the front and back.

The deque push-front operation inserts an item at the front of the deque, and the push-back operation inserts at the back of the deque.

The pop-front operation removes and returns the item at the front of the deque, and the pop-back operation removes and returns the item at the back of the deque.

Ex: After the operations “push-back 7”, “push-front 14”, “push-front 9”, and “push-back 5”, “pop-back” returns 5. A subsequent “pop-front” returns 9.

20
Q

What does the deque peek operation do?

A

In addition to pushing or popping at the front or back, a deque typically supports peeking at the front and back of the deque and determining the length. A peek operation returns an item in the deque without removing the item.

21
Q

VIEW: Common deque ADT operations.