Stacks Flashcards

1
Q

What is an abstract data type (ADT)?

A

An abstract data type (ADT) is a model for a certain class of data structures that have similar behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a stack?

A

A stack is an abstract data type that follows the Last In, First Out (LIFO) principle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False: In a stack, the first element added is the first to be removed.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the primary operations of a stack?

A

The primary operations of a stack are push, pop, and peek (or top).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fill in the blank: The operation that adds an element to the top of the stack is called ____.

A

push

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Fill in the blank: The operation that removes the top element from the stack is called ____.

A

pop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the ‘peek’ operation do?

A

The ‘peek’ operation retrieves the top element of the stack without removing it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: A stack can be implemented using arrays or linked lists.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a common use case for stacks?

A

Common use cases for stacks include expression evaluation and backtracking algorithms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True or False: A stack can grow indefinitely without a limit.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is stack overflow?

A

Stack overflow occurs when a stack exceeds its maximum capacity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is stack underflow?

A

Stack underflow occurs when a pop operation is attempted on an empty stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Multiple choice: Which of the following operations is not a standard stack operation? A) push B) pop C) enqueue D) peek

A

C) enqueue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does a stack differ from a queue?

A

A stack is LIFO while a queue is FIFO (First In, First Out).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: The maximum number of elements a stack can hold is known as its ____.

A

capacity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a real-world analogy for a stack?

A

A stack can be compared to a stack of plates where the last plate placed on top is the first one to be taken off.

17
Q

True or False: In a stack, elements can be accessed in any order.

18
Q

What data structure can be used to implement a stack?

A

A stack can be implemented using either an array or a linked list.

19
Q

What is the purpose of the ‘isEmpty’ function in a stack?

A

The ‘isEmpty’ function checks if the stack contains any elements.

20
Q

Multiple choice: Which of the following best describes a stack? A) A linear data structure B) A non-linear data structure C) A tree structure D) A graph structure

A

A) A linear data structure

21
Q

What is the main advantage of using a stack?

A

The main advantage of using a stack is its simplicity and efficiency in managing data in a LIFO manner.

22
Q

Fill in the blank: In a stack, the topmost element is the one that is ____ first.

23
Q

True or False: Stacks are commonly used in function call management in programming languages.

24
Q

What is a stack frame?

A

A stack frame is a section of the stack that contains information about a function call, including local variables and return addresses.

25
Multiple choice: Which operation would typically cause a stack underflow? A) push B) pop C) peek D) isEmpty
B) pop
26
What happens to the stack pointer when a push operation is executed?
The stack pointer moves up to point to the new top element.
27
What happens to the stack pointer when a pop operation is executed?
The stack pointer moves down to point to the new top element.