Logo/

Stacks, Queues, and Abstract Data Types

Log in

Made with ScholarlyMake flashcards like these from your own notes

Stacks, Queues, and Abstract Data Types

Questions and answers

65 cards
  1. 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.

  2. 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.

  3. 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.

  4. Question:Which index identifies the first element of a C array?

    Answer:The first index is 0.

  5. Question:How many elements does int values[10]; create?

    Answer:It creates an integer array with 10 elements, indexed 0–9.

  6. Question:Which ordering principle governs the operations of a stack?

    Answer:A stack uses LIFO, meaning Last In, First Out.

  7. Question:Where are stack items both added and removed?

    Answer:Items are added and removed at the top of the stack.

  8. Question:Why is an array-based stack initialized with top = -1?

    Answer:The value top = -1 indicates that the stack contains no items.

  9. Question:Which variable identifies the current top item in a stack?

    Answer:The variable is named top.

  10. Question:Which operation adds a new item to a stack?

    Answer:The push() operation adds an item to a stack.

  11. Question:How does top change during a normal push operation?

    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?

    Answer:The value is stored at stack[top].

  13. Question:Which operation removes the item at the stack’s top?

    Answer:The pop() operation removes the item at the top.

  14. Question:If 10, 20, and 30 are pushed, which item is popped first?

    Answer:30 is popped first.

  15. 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.

  16. Question:When 40 is at the stack’s top, what does peek() return?

    Answer:peek() returns 40 without removing it.

  17. 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.

  18. 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.

  19. Question:Which ordering principle governs the operations of a queue?

    Answer:A queue uses FIFO, meaning First In, First Out.

  20. Question:Where does an item enter and leave a queue?

    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?

    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?

    Answer:The enqueue() operation adds a new item to the rear of a queue.

  23. Question:Which operation removes an item from a queue?

    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?

    Answer:A leaves first.

  25. 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.

  26. Question:Which queue design can reuse freed array positions?

    Answer:A circular queue can reuse available positions.

  27. Question:How many values can the declaration int stack[SIZE]; hold when SIZE equals 5?

    Answer:It can hold 5 values.

  28. Question:What is the highest valid index for an array stack of size 5?

    Answer:The highest valid index is 4.

  29. Question:Why does push logic check whether top == SIZE - 1?

    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?

    Answer:It retrieves stack[top] and then decreases top after confirming that the stack is not empty.

  31. 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.

  32. 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.

  33. 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.

  34. 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.

  35. 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.

  36. Question:Why must front and rear be tracked during queue operations?

    Answer:They identify the positions used for removal and addition.

  37. 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.

  38. Question:After pushing 5, 10, and 15, popping once, and pushing 20, what is at the top?

    Answer:20.

  39. Question:When items A, B, and C are inserted in that order, which item is removed first from a stack?

    Answer:C.

  40. Question:When items A, B, and C are inserted in that order, which item is removed first from a queue?

    Answer:A.

  41. 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.

  42. Question:Which abstract data type uses enqueue(), dequeue(), front, and rear?

    Answer:Queue.

  43. Question:Which abstract data type uses push(), pop(), peek, and top?

    Answer:Stack.

  44. Question:Which three operations are identified as the main stack operations?

    Answer:push(), pop(), and peek().

  45. Question:Which variable tracks the active position of a stack?

    Answer:top.

  46. Question:What happens when a full stack receives another push operation?

    Answer:Overflow occurs.

  47. Question:Which two operations are identified as the main queue operations?

    Answer:enqueue() and dequeue().

  48. Question:Where is an item added during a queue enqueue operation?

    Answer:At the rear.

  49. Question:Where is an item removed during a queue dequeue operation?

    Answer:At the front.

  50. Question:Which ordering principle characterizes stack behavior?

    Answer:LIFO, meaning Last In, First Out.

  51. Question:Which ordering principle characterizes queue behavior?

    Answer:FIFO, meaning First In, First Out.

  52. Question:Which index is the first index of a one-dimensional array?

    Answer:0.

  53. Question:What is the highest valid index of the array stack[5]?

    Answer:4.

  54. Question:Why are control variables important in array-based abstract data types?

    Answer:They track where items are stored, added, or removed.

  55. Question:How does a stack differ from a queue in removal order?

    Answer:A stack uses LIFO, whereas a queue uses FIFO.

  56. Question:Why are boundary checks necessary for array-based abstract data types?

    Answer:They prevent invalid array access and incorrect abstract data type operations.

  57. Question:Which control variable does a stack use to track its active end?

    Answer:top.

  58. Question:Which control variables does a queue use to track its positions?

    Answer:front and rear.

  59. Question:Which stack operation adds an item, and which operation removes one?

    Answer:push() adds an item. pop() removes an item.

  60. Question:Which queue operation adds an item, and which operation removes one?

    Answer:enqueue() adds an item. dequeue() removes an item.

  61. Question:What does an abstract data type describe about a data structure?

    Answer:It describes the data structure’s behavior and operations.

  62. Question:Which pair of conditions must be checked when implementing stack and queue operations?

    Answer:Overflow and underflow.

  63. Question:How does an array-based implementation keep track of item positions?

    Answer:It uses control variables such as top, front, or rear.

  64. Question:What is the practical consequence of pushing into a full stack?

    Answer:The operation causes stack overflow.

  65. 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.