4. Stacks and Queues

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

How can you fix a broken sequence? What is created?

Delete enough items so that the Fron arrow wraps around. This creates a single contiguous sequence.

Explain LIFO

Last-In-First-Out. A stack is a LIFO storage mechanism because the last item inserted is the first one to be removed.

Whatever you can do to manipulate the data storage structure becomes our:

Methods.

What are the pros and cons of using a priority queue implemented by a simple array?

Pro: Simple and appropriate when the # of items isn't high or insertion speed isn't critical. Con: Suffers from slow insertion

Explain stacks using the work day analogy.

...

Use the postal analogy to describe stacks.

...

What are stacks allowed access to?

...

Why are stacks, queues and priority queues more abstract than arrays?

...

Explain how you would create an algorithm that matches delimiters on the stack. Include errors in your explanation.

1. Read the characters from a string one at a time. 2. Find and place the opening delimiters on the stack one at a time 3. When the program reads a closing delimiter from the input, pop the corresponding opening delimiter from the top of the stack 4. If the delimiters are not of the same type an error will occur, telling us that the string is missing either an opening or closing delimiter. If there is no opening delimiter on the stack an error will occur.

What is a deque?

A double-ended queue. You can insert items and either end & delete items from either end.

How is a priority queue different than a queue?

A priority queue items are ordered by key value so that the item with the lowest key ( or in some implementations the highest key) is always at the front. Items are inserted in the proper position to maintain the order.

What is the difference between a stack and a queue?

In a queue the first item inserted is the first to be removed (FIFO). In a stack the last item inserted is the first to be removed (LIFO)

How is "peek" different in a queue?

It "peeks" at the value of the item at the front of the queue without removing it as opposed to the last value in a stack.

What is "peek"?

It allows the user to read the value at the top of the stack with out removing it.

Where does the term queue come from?

It is a British reference to waiting in line. Fist in, first out.

What is the "push"?

Placing a data item on top of the stack.

What is "popping"?

Removing a data item from the top of the stack.

What happens to non delimiter characters?

They are not inserted onto the stack; they are ignored.

What is wrapping around? When is it useful? What is created that must be fixed?

Wrapping around allows the user to fill in new items in the queue at index zero, assuming that the queue is empty at index zero. This creates a broken sequence (the items in the queue are in two different sequences in the array).

How does the mail sorting analogy apply to the priority queue?

You insert a letter from the postman into your pile of pending letters according to priority. The higher the priority the higher the position in the pile.

Unlike a stack, the items in a queue don't always:

extend all the way down to index 0.


Set pelajaran terkait

NUR 3420 Pharmacology PrepU Ch22

View Set

Exam 2 - Unit 7 - Conflict Resolution Part 2

View Set

PART 2. THE MIDDLE AGES AND RENAISSANCE (PRELUDE 2; CHAPTERS 13-19)

View Set