Queue Flashcards

1
Q

What is the primary characteristic of a queue data structure?

a) Last-in, first-out (LIFO) behavior
b) First-in, first-out (FIFO) behavior
c) Random access
d) Hierarchical ordering

A

b) First-in, first-out (FIFO) behavior

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

Which method adds a new item to the back of a queue?

a) enqueue()
b) push()
c) insert()
d) addToBack()

A

a) enqueue()

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

What does the dequeue() method in a queue do?

a) Adds an item to the back of the queue
b) Removes the item from the back of the queue
c) Removes the item from the front of the queue
d) Moves an item to the front of the queue

A

c) Removes the item from the front of the queue

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

In a queue, what happens when the array is full and a new item needs to be added?

a) The array overwrites the oldest item
b) The array is resized to accommodate new items
c) An exception is thrown
d) The array items are cleared

A

b) The array is resized to accommodate new items

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

What is returned by the getFront() method when the queue is empty?

a) The last item added
b) The value null
c) An exception
d) An empty string

A

b) The value null

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

What must be done after removing an item in the dequeue() method?

a) Reset the queueCount to 0
b) Resize the array
c) Shift all remaining items down one index position
d) Add a placeholder at the removed index

A

c) Shift all remaining items down one index position

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

What is the default maximum size of a queue when using the no-argument constructor?

a) 5
b) 10
c) 20
d) Unlimited

A

b) 10

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

What does the toString() method in the Queue class do?

a) Returns the last item in the queue
b) Displays all items and their indexes
c) Removes all items from the queue
d) Calculates the total number of items

A

b) Displays all items and their indexes

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

Which of these describes the purpose of the resizeItemsArray() method in the Queue class?

a) Deletes old items to free up space
b) Creates a new array with more space and copies the current items into it
c) Converts the array into a list
d) Resets the queueCount to the default value

A

b) Creates a new array with more space and copies the current items into it

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

What is the primary difference between the enqueue() method and the push() method in the Stack and Queue classes?

a) enqueue() adds items at the back, while push() adds items at the front
b) enqueue() adds items at the back, while push() adds items at the top
c) enqueue() resizes the array, while push() does not
d) enqueue() is for arrays, while push() is for lists

A

b) enqueue() adds items at the back, while push() adds items at the top

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

What should the dequeue() method return if the queue is empty?

a) null
b) The last item
c) A default value
d) An error message

A

a) null

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

What is the role of the queueCount variable in the Queue class?

a) Tracks the maximum capacity of the queue
b) Tracks the number of items currently in the queue
c) Specifies the default size of the array
d) Determines the index of the front item

A

b) Tracks the number of items currently in the queue

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

What output is expected when the dequeue() method is called on a queue containing ‘Star Wars’, ‘Blade Runner’, and ‘The Empire Strikes Back’?

a) Blade Runner
b) Star Wars
c) The Empire Strikes Back
d) null

A

b) Star Wars

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

Why does the toString() method iterate through the items array in the Queue class?

a) To check for duplicate items
b) To display the items in order from front to back
c) To remove all null values
d) To count the number of items

A

b) To display the items in order from front to back

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

What happens when the dequeue() method is called multiple times on a queue?

a) Items are removed and indexes shift downward each time
b) Items are removed, but indexes remain the same
c) An exception is thrown after the first call
d) The queue resets after two calls

A

a) Items are removed and indexes shift downward each time

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