Stack: 20 flashcards

All 20 flashcards from this kit, free and with no sign-up.

1. What is a stack?

Show the answer

A linear data structure that follows the Last In, First Out (LIFO) principle.

2. What does LIFO stand for?

Show the answer

Last In, First Out

3. What are the primary operations on a stack?

Show the answer

**Push** (insert), **Pop** (remove), **Peek** (access top), and **isEmpty** (check if empty).

4. What does the push operation do?

Show the answer

Adds an element to the top of the stack.

5. What does the pop operation do?

Show the answer

Removes and returns the top element of the stack.

6. What does the peek operation do?

Show the answer

Returns the top element without removing it.

7. What is the time complexity of push and pop operations on a stack?

Show the answer

$O(1)$

8. What is the space complexity of a stack?

Show the answer

$O(n)$ where $n$ is the number of elements in the stack.

9. What is a stack overflow?

Show the answer

An error that occurs when trying to push an element onto a full stack.

10. What is a stack underflow?

Show the answer

An error that occurs when trying to pop or peek from an empty stack.

11. How can a stack be implemented?

Show the answer

Using an **array** or a **linked list**.

12. What is the advantage of implementing a stack using a linked list?

Show the answer

It can dynamically grow and shrink, avoiding fixed capacity limitations.

13. What is the disadvantage of implementing a stack using an array?

Show the answer

The stack has a fixed capacity and cannot grow beyond it.

14. What is a real-world example of a stack?

Show the answer

A stack of plates, where you add and remove plates from the top.

15. What is the application of a stack in function calls?

Show the answer

The call stack keeps track of function calls and local variables.

16. How is a stack used in expression evaluation?

Show the answer

Stacks are used to evaluate arithmetic expressions, such as converting infix to postfix and evaluating postfix expressions.

17. What is the postfix expression for the infix expression $A + B$?

Show the answer

$A B +$

18. How does a stack help in checking balanced parentheses?

Show the answer

Push opening parentheses onto the stack; for each closing parenthesis, pop and check if it matches the corresponding opening one.

19. What is the top of a stack?

Show the answer

The most recently added element that is accessible for pop or peek.

20. What is the bottom of a stack?

Show the answer

The first element that was pushed onto the stack.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages