Unit summary

  • A stack is LIFO, with push and pop at the top, held in an array or a linked list.
  • Expressions can be infix, prefix or postfix, and a stack converts infix to postfix and evaluates postfix.
  • Recursion solves a problem through smaller copies of itself, with a base case, using the runtime stack.
  • Factorial, GCD, Fibonacci and Towers of Hanoi are classic recursive problems.
  • A queue is FIFO, with insertion at the rear and deletion at the front.
  • Circular queues reuse space, deques allow both ends, and priority queues serve by priority.

Glossary

Term Meaning
Activation record The stack frame of a function call.
Base case The case solved without recursion.
Circular queue A queue whose array wraps around.
Deque A double-ended queue.
Dequeue Remove from the front of a queue.
Enqueue Insert at the rear of a queue.
Infix Operator between operands.
Overflow Inserting into a full structure.
Polish notation Another name for prefix notation.
Pop Remove the top element of a stack.
Postfix Operator after operands.
Prefix Operator before operands.
Priority queue A queue served by priority.
Push Insert an element on a stack.
Queue A FIFO linear structure.
Recursion A function calling itself on a smaller problem.
Stack A LIFO linear structure with one open end.
Underflow Deleting from an empty structure.

Question bank

Short Answer Questions (2 marks each)

  1. Define a stack.
  2. What is stack overflow?
  3. Convert A + B × C to postfix.
  4. What is Polish notation?
  5. Define recursion.
  6. What is the runtime stack?
  7. Define a queue.
  8. What is a circular queue?
  9. What is a deque?
  10. What is a priority queue?

Medium Answer Questions (5 marks each)

  1. Implement push and pop using an array.
  2. Implement a stack using a linked list.
  3. Convert (A + B) × C − D / E to postfix using a stack.
  4. Evaluate the postfix expression 6 2 3 + − 3 8 2 / + ×.
  5. Explain the Towers of Hanoi problem and its recursive solution.
  6. Implement a circular queue using an array.

Long Answer Questions (15 marks each)

  1. Explain stacks, their array and linked list representations, and their applications.
  2. Explain infix, prefix and postfix notation, the conversion of infix to postfix and the evaluation of postfix.
  3. Explain recursion and the runtime stack, with factorial, GCD, Fibonacci and Towers of Hanoi.
  4. Explain queues and their types: simple, circular, deque and priority queue, with their applications.

Sources

  • Official BCA syllabus Data Structures, course code 25BCA402DS02, Unit III