Made with ScholarlyMake flashcards like these from your own notes
Question:Which information does an Abstract Data Type describe?
Answer:An ADT describes the data and the operations that can be performed on that data.
Question:How does an ADT differ from a particular implementation?
Answer:An ADT specifies what the data structure does, not exactly how it is implemented.
Question:How does a one-dimensional array organize its values?
Answer:It stores a collection of values of the same data type in a sequence.
Question:Which index identifies the first element of a C array?
Answer:The first index is 0.
Question:How many elements does int values[10]; create?
Answer:It creates an integer array with 10 elements, indexed 0–9.
Question:Which ordering principle governs the operations of a stack?
Answer:A stack uses LIFO, meaning Last In, First Out.
Question:Where are stack items both added and removed?
Answer:Items are added and removed at the top of the stack.
Question:Why is an array-based stack initialized with top = -1?
Answer:The value top = -1 indicates that the stack contains no items.
Question:Which variable identifies the current top item in a stack?
Answer:The variable is named top.
Question:Which operation adds a new item to a stack?
Answer:The push() operation adds an item to a stack.
Question:How does top change during a normal push operation?
Answer:The value of top increases by 1 before the new value is stored.
Question:Which array position receives the value after top is incremented?
Answer:The value is stored at stack[top].
Question:Which operation removes the item at the stack’s top?
Answer:The pop() operation removes the item at the top.
Question:If 10, 20, and 30 are pushed, which item is popped first?
Answer:30 is popped first.
Question:How does peek() differ from pop() in a stack?
Answer:peek() returns or views the top item without removing it; pop() removes the top item.
Question:When 40 is at the stack’s top, what does peek() return?
Answer:peek() returns 40 without removing it.
Question:When does stack overflow occur during an insertion attempt?
Answer:Stack overflow occurs when an attempt is made to push onto a full stack.
Question:When does stack underflow occur during a removal attempt?
Answer:Stack underflow occurs when an attempt is made to pop from an empty stack.
Question:Which ordering principle governs the operations of a queue?
Answer:A queue uses FIFO, meaning First In, First Out.
Question:Where does an item enter and leave a queue?
Answer:An item enters at the rear and leaves from the front.
Question:Which variables identify the operational ends of an array-based queue?
Answer:front identifies where removal occurs, and rear identifies where the next item is added.
Question:Which operation adds a new item to a queue?
Answer:The enqueue() operation adds a new item to the rear of a queue.
Question:Which operation removes an item from a queue?
Answer:The dequeue() operation removes an item from the front of a queue.
Question:If A, B, and C enter a queue in that order, which leaves first?
Answer:A leaves first.
Question:Why can a simple linear array queue become unable to accept items?
Answer:It can become full when rear reaches the last array position, so no more items can be added using that arrangement.
Question:Which queue design can reuse freed array positions?
Answer:A circular queue can reuse available positions.
Question:How many values can the declaration int stack[SIZE]; hold when SIZE equals 5?
Answer:It can hold 5 values.
Question:What is the highest valid index for an array stack of size 5?
Answer:The highest valid index is 4.
Question:Why does push logic check whether top == SIZE - 1?
Answer:The condition checks whether the stack is full before another item is inserted.
Question:How does typical pop logic retrieve and remove the top item?
Answer:It retrieves stack[top] and then decreases top after confirming that the stack is not empty.
Question:How do stacks and queues differ in ordering and insertion operations?
Answer:A stack uses LIFO and push for insertion. A queue uses FIFO and enqueue for insertion.
Question:Which real-world arrangement models a stack, and why?
Answer:A pile of plates models a stack because the last plate placed on top is the first one removed.
Question:Which real-world arrangement models a queue, and why?
Answer:People waiting in a line model a queue because the first person in line is served first.
Question:Starting with top = -1, what value is removed after pushing 10, 20, and 30, then popping once?
Answer:30 is removed and top becomes 1.
Question:Starting with front = 0 and rear = -1, what value is removed after enqueuing 10, 20, and 30, then dequeuing once?
Answer:10 is removed and front becomes 1.
Question:Why must front and rear be tracked during queue operations?
Answer:They identify the positions used for removal and addition.
Question:Given int stack[5]; and int top = 4;, what happens when another value is pushed?
Answer:No value can be pushed. The stack is full because the highest valid index is 4. Another push would cause overflow.
Question:After pushing 5, 10, and 15, popping once, and pushing 20, what is at the top?
Answer:20.
Question:When items A, B, and C are inserted in that order, which item is removed first from a stack?
Answer:C.
Question:When items A, B, and C are inserted in that order, which item is removed first from a queue?
Answer:A.
Question:Why should a push function test whether top == SIZE - 1 before adding an item?
Answer:To prevent adding beyond the last valid array position and causing stack overflow.
Question:Which abstract data type uses enqueue(), dequeue(), front, and rear?
Answer:Queue.
Question:Which abstract data type uses push(), pop(), peek, and top?
Answer:Stack.
Question:Which three operations are identified as the main stack operations?
Answer:push(), pop(), and peek().
Question:Which variable tracks the active position of a stack?
Answer:top.
Question:What happens when a full stack receives another push operation?
Answer:Overflow occurs.
Question:Which two operations are identified as the main queue operations?
Answer:enqueue() and dequeue().
Question:Where is an item added during a queue enqueue operation?
Answer:At the rear.
Question:Where is an item removed during a queue dequeue operation?
Answer:At the front.
Question:Which ordering principle characterizes stack behavior?
Answer:LIFO, meaning Last In, First Out.
Question:Which ordering principle characterizes queue behavior?
Answer:FIFO, meaning First In, First Out.
Question:Which index is the first index of a one-dimensional array?
Answer:0.
Question:What is the highest valid index of the array stack[5]?
Answer:4.
Question:Why are control variables important in array-based abstract data types?
Answer:They track where items are stored, added, or removed.
Question:How does a stack differ from a queue in removal order?
Answer:A stack uses LIFO, whereas a queue uses FIFO.
Question:Why are boundary checks necessary for array-based abstract data types?
Answer:They prevent invalid array access and incorrect abstract data type operations.
Question:Which control variable does a stack use to track its active end?
Answer:top.
Question:Which control variables does a queue use to track its positions?
Answer:front and rear.
Question:Which stack operation adds an item, and which operation removes one?
Answer:push() adds an item. pop() removes an item.
Question:Which queue operation adds an item, and which operation removes one?
Answer:enqueue() adds an item. dequeue() removes an item.
Question:What does an abstract data type describe about a data structure?
Answer:It describes the data structure’s behavior and operations.
Question:Which pair of conditions must be checked when implementing stack and queue operations?
Answer:Overflow and underflow.
Question:How does an array-based implementation keep track of item positions?
Answer:It uses control variables such as top, front, or rear.
Question:What is the practical consequence of pushing into a full stack?
Answer:The operation causes stack overflow.
Question:How can operation names reveal which abstract data type a program implements?
Answer:enqueue() and dequeue() indicate a queue, whereas push(), pop(), peek, and top indicate a stack.