Chapter 20 Stacks and Queues

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/29

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

30 Terms

1
New cards

A ______ is a collection of items that allows addition and removal of items in a last-infirst-out manner.

stack

2
New cards

A stack can be viewed as an abstract data type that supports three main operations, traditionally called ____ ______ ____ ____.

push, peek, and pop

3
New cards

The _____ operation takes a single item and adds it to the top of the stack

push

4
New cards

The ____ operation returns the item currently at the top of the stack, but does not remove it.

peek

5
New cards

The _____ operation removes (and returns) the item currently stored at the top of the stack.

pop

6
New cards

A ______is just a list that enforces last-in-first-out access

stack

7
New cards

1. 20.1 What is the common name for an operation that adds an element to a stack?

push

8
New cards

2. 20.2 What is the common name for an operation that removes an element from a stack?

pop

9
New cards

3. 20.3 What should a stack method for removing an item do when the stack is empty?

Throw an exception

10
New cards

4. 20.4 In what order are elements added and removed from a stack?

Last in first out

11
New cards

5. 20.5 Cite an example from everyday life where a collection of items behaves like a stack.

Some examples are a stack of plates or trays in a cafeteria, a line of cars parked single file in a narrow driveway, and a person wearing an undershirt, a shirt, a jacket, and an overcoat.

12
New cards

A ______ is a collection of items that is accessed in a first-in-first-out fashion.

queue

13
New cards

add a new item x to the rear of the queue

enqueue(x)

14
New cards

remove and return the item at the front of the queue

dequeue( )

15
New cards

check if the queue is empty

empty( )

16
New cards

return, but do not remove, the item at the front of the queue

peek( )

17
New cards

1. 20.6 What is the common name for an operation that adds an element to a queue?

enqueue

18
New cards

2. 20.7 In what order are elements added and removed from a queue?

first in first out

19
New cards

3. 20.8 Cite an example of a queue from everyday life.

Some examples are a grocery store checkout line, a line of cars going through a toll booth.

20
New cards

4. 20.9 In an array implementation of a queue, why is it necessary to treat the array as a circular buffer?

By the time the add operation reaches the end of the array, the remove operation may have emptied the spaces of the beginning of the array, allowing the add operation to wrap around and start storing elements at the beginning. Similarly, when the remove empties spaces at the end of the array, it should wrap around to the beginning.

21
New cards

1. A collection that is accessed in first-in-first-out fashion is called .
1. a stack
2. a queue
3. a linked list
4. an array-based collection

a queue

22
New cards

2. A collection that is accessed in last-in-first-out fashion is called .
1. a stack
2. a queue
3. a linked list
4. none of the above

a stack

23
New cards

3. The order in which cars go through a toll booth is best described as .
1. a stack
2. a queue
3. a linked list
4. none of the above

a queue

24
New cards

4. The concept of seniority, which some employers use to hire and fire workers is .
1. a stack
2. a queue
3. a linked list
4. none of the above

a stack

25
New cards

5. The stack method that returns an element from the stack without removing it is .
1. pop
2. push
3. peek
4. spy

peek

26
New cards

6. If the stack method push is called on an empty stack, .
1. it throws an EmptyStackException
2. it adds its argument to the stack
3. it calls the stack method empty
4. none of the above

it adds its argument to the stack

27
New cards

7. True or False: You can use the JCF stack to directly create a stack of int.

False

28
New cards

8. True or False: If pop is called on an empty stack, it will not return until the user puts something on the stack.

False

29
New cards

9. True or False: When using an array to implement a stack, the push method will wrap around to the beginning of the stack when it reaches the end.

False

30
New cards

10. True or False: In a linked implementation of a queue, the references front and rear can only be equal if the queue is empty.

False