Chapter 5: Stacks and Queues

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play

1/14

flashcard set

Earn XP

Description and Tags

Practice flashcards covering the concepts, operations, implementations, and applications of Stacks and Queues from Chapter 5.

15 Terms

1
New cards

What does the acronym LIFO stand for in relation to a stack data structure?

Last in, first out.

2
New cards

According to the typical stack ADT specification, what are the precondition and postcondition of the pop() method?

The precondition is self.size()>0\text{self.size()} > 0, and the postcondition is that it removes and returns the top element of the stack.

3
New cards

What information is pushed onto the run-time stack when a function is called in modern computer systems?

Information about the function, such as the values of local variables and the return address where the program left off before calling the function.

4
New cards

Why does a simple counter approach fail to verify balanced grouping markers when multiple types are present?

A simple counter cannot verify that each closing marker matches the most recent unmatched opening marker of the proper type, falsely allowing improperly nested expressions such as [(]).

5
New cards

What is reverse Polish notation commonly known as, and what is its main advantage over infix notation?

It is commonly known as postfix notation, and its main advantage is that parentheses are not necessary to modify or specify the order of operations.

6
New cards

In the stack-based algorithm for evaluating a postfix expression, what actions occur when an operator is encountered?

Two numbers are popped off the stack, the operator is applied to those two numbers, and the result is pushed back onto the stack.

7
New cards

What type of stack-based computer recognizes the exact set of languages that can be described by context-free grammars (CFGs)?

A pushdown automaton.

8
New cards

How does the ordering discipline of a queue differ from that of a stack?

A queue is a first in, first out (FIFO) structure where items are added at the back and removed from the front, whereas a stack is a last in, first out (LIFO) structure.

9
New cards

In the two-phase palindrome verification program, what complementary roles are played by the queue and the stack?

The queue stores the characters to yield them in their original forward sequence, while the stack stores them to yield them in reversed order.

10
New cards

How can a singly linked list implementation of a queue achieve Θ(1)\Theta(1) time for both enqueue and dequeue operations?

By maintaining references to both the first node (front/head) and the last node (tail), performing insertions at the end of the linked list and removals from the front.

11
New cards

In a circular array implementation of a queue with an array of size 1010, what expression is used to advance the tail index?

tail=(tail+1)(mod10)\text{tail} = (\text{tail} + 1) \pmod{10}

12
New cards

In a circular array queue of capacity nn, why does tracking only head and tail indices create an ambiguity between an empty queue and a full queue?

Both an empty queue and a full queue result in the identical condition head==tail\text{head} == \text{tail}, because adding nn items causes the tail pointer to wrap completely around back to the head.

13
New cards

What famous maxim regarding code optimization was stated by computer scientist Tony Hoare?

"Premature optimization is the root of all evil."

14
New cards

In the infix-to-postfix conversion algorithm, what sequence of actions is triggered when the token is a right parenthesis?

While the top item on the stack is not a left parenthesis, the item is popped from the stack and appended to the postfix expression; then, the left parenthesis is popped from the stack.

15
New cards

What is the primary difference between a time-driven simulation and an event-driven simulation in queuing analysis?

A time-driven simulation increments a simulated clock one tick at a time and inspects what occurs at each tick, whereas an event-driven simulation jumps the clock ahead directly to the next scheduled event.