STACK Flashcards

(54 cards)

1
Q

What is a stack?

A

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

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

Which operations are primarily associated with stacks?

A

Push, pop, and peek.

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

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

A

True.

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

What is the time complexity of push and pop operations in a stack?

A

O(1).

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

Fill in the blank: A stack is often used to implement _____.

A

function calls.

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

What is the main use of a stack in programming?

A

To keep track of function calls and local variables.

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

Which of the following is a common application of stacks?

A

Undo mechanisms in software.

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

What does the ‘peek’ operation do in a stack?

A

It retrieves the top element without removing it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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
10
Q

What happens when you try to pop an element from an empty stack?

A

It results in an underflow error.

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

What is the maximum size of a stack implemented with a fixed-size array?

A

It is limited by the size of the array.

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

Which data structure is used to reverse a string?

A

A stack.

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

What is the stack pointer?

A

A pointer that indicates the top of the stack.

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

Fill in the blank: The stack follows the _____ principle.

A

Last In, First Out (LIFO).

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

What is a stack overflow?

A

It occurs when there is no more space in the stack to add new elements.

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

Multiple Choice: Which one of the following is NOT a valid stack operation?

A

Insert at a specific position.

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

True or False: The stack data structure can be used for depth-first search in graphs.

A

True.

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

What does it mean to ‘push’ an element onto a stack?

A

To add an element to the top of the stack.

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

What is the result of popping an element from a stack with one element?

A

The stack becomes empty.

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

Which of the following is a characteristic of a stack?

A

Elements are added and removed from the same end.

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

What is the primary difference between a stack and 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
22
Q

Fill in the blank: In recursive function calls, each call is stored in a _____.

23
Q

What is a stack frame?

A

A structure that contains information about a function call, including local variables and return address.

24
Q

Multiple Choice: Which application uses stacks?

A

Backtracking algorithms.

25
What is the stack data structure commonly used for in compilers?
To manage function calls and local variables.
26
True or False: A stack can dynamically grow in size.
True, if implemented using a linked list.
27
What is the key advantage of using a stack?
It allows for efficient management of data in LIFO order.
28
What is the purpose of the 'isEmpty' function in a stack implementation?
To check if the stack has no elements.
29
Which operation would you use to access the top element of a stack without removing it?
Peek.
30
What is a common problem that can occur with stack-based algorithms?
Stack overflow.
31
True or False: Stacks can be implemented using circular linked lists.
True.
32
What type of problems can be solved using stacks?
Problems that require backtracking, such as maze solving.
33
Fill in the blank: The _____ data structure is used to reverse the order of elements.
stack.
34
What does it mean to 'pop' an element from a stack?
To remove the element from the top of the stack.
35
Multiple Choice: Which of the following best describes a stack?
A collection of elements with a specific order of access.
36
What is the stack's behavior during recursion?
Each recursive call adds a new stack frame.
37
True or False: You can access elements in a stack randomly.
False.
38
What happens to the stack when a function call is completed?
The stack frame for that function is removed.
39
What is a common use of stacks in web browsers?
To manage the history of visited pages.
40
Fill in the blank: In a stack, the _____ operation adds an element.
push.
41
What is the typical implementation of a stack in programming languages?
Using an array or a linked list.
42
Multiple Choice: Which of the following is a real-world analogy for a stack?
A stack of plates.
43
True or False: A stack can be used to evaluate expressions in postfix notation.
True.
44
What is the primary data structure used to implement undo functionality in applications?
Stack.
45
What are the two main types of stacks?
Static stack and dynamic stack.
46
Fill in the blank: A stack is often referred to as a _____ structure.
linear.
47
What is the effect of pushing elements onto a stack until it is full?
It causes a stack overflow error.
48
What is the role of a stack in function calls?
To store return addresses and local variables.
49
True or False: You can push and pop elements in any order in a stack.
False.
50
What is the main disadvantage of using a fixed-size stack?
It can lead to stack overflow if the size limit is exceeded.
51
Multiple Choice: Which of the following operations is not typically associated with stacks?
Searching for an element.
52
What happens during a stack underflow?
An attempt is made to pop an element from an empty stack.
53
Fill in the blank: Stacks are often used in algorithms that require _____.
backtracking.
54
What does a stack's 'top' refer to?
The most recently added element that is available for removal.