Essential Stacks & Queues in Programming Fundamentals Quiz

Explore the core principles of stacks and queues, including their order, operations, applications, and representations in programming. Ideal for beginners looking to strengthen their understanding of essential data structures.

  1. Stack Order Principle

    Which order does a stack follow when storing and retrieving elements?

    1. FIFO
    2. LIFO
    3. Priority-based
    4. Random

    Explanation: Stack follows Last-In-First-Out (LIFO): the most recently added item is the first to be removed. FIFO refers to queues, not stacks. Random and Priority-based are not typical for stack data structures.

  2. Queue Order Principle

    Which order does a queue follow for element insertion and removal?

    1. Random
    2. FIFO
    3. LIFO
    4. Priority-based

    Explanation: Queues follow First-In-First-Out (FIFO), meaning the earliest added element is served first. LIFO is for stacks. Random and Priority-based do not describe standard queue behavior.

  3. Infix to Postfix Conversion

    What is the postfix expression for the infix expression (A+B)*C?

    1. C*AB+
    2. AB+C*
    3. A+B*C
    4. A*B+C

    Explanation: By converting infix to postfix, (A+B)*C becomes AB+C*. The other expressions either fail to preserve operator precedence or mix infix/postfix notation incorrectly.

  4. Recursion Data Structure

    Which data structure is commonly used for supporting recursion in programming languages?

    1. Array
    2. Queue
    3. Stack
    4. Heap

    Explanation: Recursion uses a stack to store function call contexts. Queues do not support LIFO operations needed. Arrays are used for static data, and heaps are for memory management.

  5. Inefficient Queue Operation

    Which operation is not efficiently possible in a simple linear queue?

    1. Deletion from rear
    2. Deletion from front and insertion at rear (simultaneously)
    3. Insertion at front and rear
    4. Insertion at front

    Explanation: In a simple queue, deletion from front and insertion at rear often leads to inefficient use of space as array positions become unusable. The other options describe specific but possible operations.

  6. Circular Queue Advantage

    What is the primary advantage of using a circular queue over a simple linear queue?

    1. Supports LIFO order
    2. Simplifies recursion
    3. Allows variable size
    4. Efficient memory reuse

    Explanation: Circular queues efficiently reuse space by wrapping around, preventing wasted memory. Variable size is not ensured; recursion and LIFO order are unrelated to queue structure.

  7. Algorithm Using a Queue

    Which algorithm commonly uses a queue data structure?

    1. Depth-First Search
    2. Breadth-First Search (BFS)
    3. Heap Sort
    4. Bubble Sort

    Explanation: BFS employs a queue to explore nodes in levels. Depth-First Search uses a stack, while Heap Sort and Bubble Sort do not inherently use queues for processing.

  8. Stack Application

    Two stacks can be used together to implement which other data structure?

    1. Queue
    2. Linked List
    3. Priority Queue
    4. Circular Queue

    Explanation: Two stacks can simulate queue behavior, providing FIFO operations. Priority Queue and Circular Queue need special handling, and Linked List is structurally different.

  9. Stack Space Complexity

    What is the space complexity of implementing a stack using an array of size n?

    1. O(log n)
    2. O(1)
    3. O(n^2)
    4. O(n)

    Explanation: An n-sized array uses O(n) space, as space grows linearly with the number of elements. O(1) is incorrect for dynamic storage; O(log n) and O(n^2) are unrelated to basic stack size.

  10. Postfix Evaluation

    What is the result of evaluating the postfix expression '6 3 / 2 * 5 +'?

    1. 11
    2. 9
    3. 5
    4. 1

    Explanation: The expression evaluates as (6/3)=2, then 2*2=4, then 4+5=9. Alternatives reflect common mistakes like misapplied operator precedence or result.