Questions Chapter 4 Flashcards

1
Q

Suppose you push 10, 20, 30, and 40 onto the stack. Then you pop three items. Which one is left on the stack?

A

10

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

Which of the following is true?

a. The pop operation on a stack is considerably simpler than the remove operation on a queue.
b. The contents of a queue can wrap around, while those of a stack cannot.
c. The top of a stack corresponds to the front of a queue.
d. In both the stack and the queue, items removed in sequence are taken from increasingly high index cells in the array.

A

b. The contents of a queue can wrap around, while those of a stack cannot.

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

What do LIFO and FIFO mean?

A

Last In First Out, First In First Out.

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

True or False: A stack or a queue often serves as the underlying mechanism on which an ADT array is based.

A

False.

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

Assume an array is numbered with index 0 on the left. A queue representing a line of movie-goers, with the first to arrive numbered 1, has the ticket window on the right. Then:

a. there is no numerical correspondence between the index numbers and the movie-goer numbers
b. the array index numbers and the movie-goer numbers increase in opposite left-right directions
c. the array index numbers correspond numerically to the locations in the line of movie goers.
d. the movie-goers and the items in the array move in the same direction.

A

b. the array index numbers and the movie-goer numbers increase in opposite left-right directions

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

As other items are inserted and removed, does a particular item in a queue move along the array from lower to higher indices, or higher to lower?

A

Doesn’t move.

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

Suppose you insert 15, 25, 35, 45 into a queue. Then you remove three items. Which one is left?

A

45

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

True or False: Pushing and popping items on a stack and inserting and removing items in a queue all take O(N) time.

A

False

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

A queue might be used to hold:

a. the items to be sorted in an insertion sort
b. reports of a variety of imminent attacks on the start ship Enterprise
c. keystrokes made by a computer user writing a letter
d. symbols in algebraic expression being evaluated

A

c. keystrokes made by a computer user writing a letter.

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

Inserting an item into a typical priority queue takes what big O time?

A

O(N)

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

The term priority in a priority queue means that:

a. the highest priority items are inserted first
b. the programmer must prioritize access to the underlying array
c. the underlying array is sorted by the priority of items
d. the lowest priority items are deleted first

A

c. the underlying array is sorted by the priority of the items

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

True or False: At least one of the methods in the priorityQ.java program (Listing 4.6) uses a linear search.

A

True

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

One difference between a priority queue and an ordered array is that:

a. the lowest-priority item cannot be extracted as easily from the array as it can from the priority queue.
b. the array must be ordered while the priority queue need not be.
c. the highest priority item can be extracted easily from the priority queue but not from the array
d. all of the above.

A

b. the array must be ordered while the priority queue need not be.

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

A priority queue might be used to hold:

a. passengers to be picked up by a taxi from different parts of the city
b. keystrokes made at a computer keyboard
c. squares on a chessboard in a game program.
d. planets in a solar system simulation.

A

a. passengers to be picked up by a taxi from different parts of the city.

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

A stack allows access to the ________ item inserted.

A

last

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

A queue allows access to the ________ item inserted.

A

first

17
Q

A priority queue allows access to the _________ item inserted.

A

smallest (or sometimes largest) item.

18
Q

In _______ notation, the operator follows the two operands.

A

postfix notation