/
Stacks, Queues, and Abstract Data Types
Save to my account
Sign up
Stacks, Queues, and Abstract Data Types
Stacks, Queues, and Abstract Data Types
Study
1
Question
Which information does an Abstract Data Type describe?
Page 2
Answer
An ADT describes the data and the operations that can be performed on that data.
2
Question
How does an ADT differ from a particular implementation?
Page 2
Answer
An ADT specifies what the data structure does, not exactly how it is implemented.
3
Question
How does a one-dimensional array organize its values?
Page 2
Answer
It stores a collection of values of the same data type in a sequence.
4
Question
Which index identifies the first element of a C array?
Page 2
Answer
The first index is 0.
5
Question
How many elements does int values[10]; create?
Page 2
Answer
It creates an integer array with 10 elements, indexed 0–9.
6
Question
Which ordering principle governs the operations of a stack?
Page 3
Answer
A stack uses LIFO, meaning Last In, First Out.
7
Question
Where are stack items both added and removed?
Page 3
Answer
Items are added and removed at the top of the stack.
8
Question
Why is an array-based stack initialized with top = -1?
Page 3
Answer
The value top = -1 indicates that the stack contains no items.
9
Question
Which variable identifies the current top item in a stack?
Page 3
Answer
The variable is named top.
10
Question
Which operation adds a new item to a stack?
Page 4
Answer
The push() operation adds an item to a stack.
11
Question
How does top change during a normal push operation?
Page 4
Answer
The value of top increases by 1 before the new value is stored.
12
Question
Which array position receives the value after top is incremented?
Page 4
Answer
The value is stored at stack[top].
13
Question
Which operation removes the item at the stack’s top?
Page 4
Answer
The pop() operation removes the item at the top.
14
Question
If 10, 20, and 30 are pushed, which item is popped first?
Page 4
Answer
30 is popped first.
15
Question
How does peek() differ from pop() in a stack?
Page 4
Answer
peek() returns or views the top item without removing it; pop() removes the top item.
16
Question
When 40 is at the stack’s top, what does peek() return?
Page 4
Answer
peek() returns 40 without removing it.
17
Question
When does stack overflow occur during an insertion attempt?
Page 5
Answer
Stack overflow occurs when an attempt is made to push onto a full stack.
18
Question
When does stack underflow occur during a removal attempt?
Page 5
Answer
Stack underflow occurs when an attempt is made to pop from an empty stack.
19
Question
Which ordering principle governs the operations of a queue?
Page 6
Answer
A queue uses FIFO, meaning First In, First Out.
20
Question
Where does an item enter and leave a queue?
Page 6
Answer
An item enters at the rear and leaves from the front.
21
Question
Which variables identify the operational ends of an array-based queue?
Page 6
Answer
front identifies where removal occurs, and rear identifies where the next item is added.
22
Question
Which operation adds a new item to a queue?
Page 7
Answer
The enqueue() operation adds a new item to the rear of a queue.
23
Question
Which operation removes an item from a queue?
Page 7
Answer
The dequeue() operation removes an item from the front of a queue.
24
Question
If A, B, and C enter a queue in that order, which leaves first?
Page 7
Answer
A leaves first.
25
Question
Why can a simple linear array queue become unable to accept items?
Page 7
Answer
It can become full when rear reaches the last array position, so no more items can be added using that arrangement.
26
Question
Which queue design can reuse freed array positions?
Page 7
Answer
A circular queue can reuse available positions.
27
Question
How many values can the declaration int stack[SIZE]; hold when SIZE equals 5?
Page 8
Answer
It can hold 5 values.
28
Question
What is the highest valid index for an array stack of size 5?
Page 8
Answer
The highest valid index is 4.
29
Question
Why does push logic check whether top == SIZE - 1?
Page 8
Answer
The condition checks whether the stack is full before another item is inserted.
30
Question
How does typical pop logic retrieve and remove the top item?
Page 9
Answer
It retrieves stack[top] and then decreases top after confirming that the stack is not empty.