Free Online Flashcard Deck

5 Stacks and Queues Free Online FlashCards

Study 5 Stacks and Queues with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What access rule does a stack follow?

Back

A stack follows last in, first out (LIFO): the most recently inserted element is removed first.

02
Front

What access rule does a queue ordinarily follow?

Back

A queue ordinarily follows first in, first out (FIFO): the earliest inserted element is removed first.

03
Front

How do `push`, `pop`, and `peek` differ in a stack?

Back

`push(x)` inserts `x` at the top, `pop()` removes and returns the top element, and `peek()` returns it without removing it.

04
Front

How do `enqueue`, `dequeue`, and `front` operate on a queue?

Back

`enqueue(x)` inserts at the rear, `dequeue()` removes and returns the front element, and `front()` or `peek()` inspects the front without removal.

05
Front

What are underflow and overflow?

Back

Underflow occurs when an element is removed from or examined in an empty structure. Overflow can occur when inserting into a full bounded structure.

06
Front

Why use a circular buffer for an array-based queue?

Back

A circular buffer lets queue indices wrap around, avoiding shifts of the remaining elements after each dequeue.

07
Front

Why can dynamic-array insertion be O(1) amortized?

Back

Geometric growth makes a sequence of dynamic-array insertions O(n) total, so each insertion is O(1) amortized despite occasional O(n) resizing.

08
Front

Why does a linked-list queue maintain front and rear pointers?

Back

A linked-list queue needs both front and rear pointers: front supports constant-time removal, while rear supports constant-time insertion.

09
Front

What is the main cost of a naive shifting array queue?

Back

A naive array queue can make dequeue O(n) because it shifts every remaining element toward the front after removal.

10
Front

What is a deque?

Back

A deque supports insertion, removal, and inspection at both ends, so it can function as either a queue or a stack.

11
Front

How does a call stack manage nested function calls?

Back

A call stack pushes an activation record when a function is called and pops it when the function returns, producing return order in LIFO sequence.

12
Front

How can a stack check whether `([{}])` has matching delimiters?

Back

Push each opening delimiter; when a closing delimiter appears, it must match the most recently pushed opening delimiter.