STACK Flashcards

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 _____.

A

stack frame.

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
Q

What is the stack data structure commonly used for in compilers?

A

To manage function calls and local variables.

26
Q

True or False: A stack can dynamically grow in size.

A

True, if implemented using a linked list.

27
Q

What is the key advantage of using a stack?

A

It allows for efficient management of data in LIFO order.

28
Q

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

A

To check if the stack has no elements.

29
Q

Which operation would you use to access the top element of a stack without removing it?

30
Q

What is a common problem that can occur with stack-based algorithms?

A

Stack overflow.

31
Q

True or False: Stacks can be implemented using circular linked lists.

32
Q

What type of problems can be solved using stacks?

A

Problems that require backtracking, such as maze solving.

33
Q

Fill in the blank: The _____ data structure is used to reverse the order of elements.

34
Q

What does it mean to ‘pop’ an element from a stack?

A

To remove the element from the top of the stack.

35
Q

Multiple Choice: Which of the following best describes a stack?

A

A collection of elements with a specific order of access.

36
Q

What is the stack’s behavior during recursion?

A

Each recursive call adds a new stack frame.

37
Q

True or False: You can access elements in a stack randomly.

38
Q

What happens to the stack when a function call is completed?

A

The stack frame for that function is removed.

39
Q

What is a common use of stacks in web browsers?

A

To manage the history of visited pages.

40
Q

Fill in the blank: In a stack, the _____ operation adds an element.

41
Q

What is the typical implementation of a stack in programming languages?

A

Using an array or a linked list.

42
Q

Multiple Choice: Which of the following is a real-world analogy for a stack?

A

A stack of plates.

43
Q

True or False: A stack can be used to evaluate expressions in postfix notation.

44
Q

What is the primary data structure used to implement undo functionality in applications?

45
Q

What are the two main types of stacks?

A

Static stack and dynamic stack.

46
Q

Fill in the blank: A stack is often referred to as a _____ structure.

47
Q

What is the effect of pushing elements onto a stack until it is full?

A

It causes a stack overflow error.

48
Q

What is the role of a stack in function calls?

A

To store return addresses and local variables.

49
Q

True or False: You can push and pop elements in any order in a stack.

50
Q

What is the main disadvantage of using a fixed-size stack?

A

It can lead to stack overflow if the size limit is exceeded.

51
Q

Multiple Choice: Which of the following operations is not typically associated with stacks?

A

Searching for an element.

52
Q

What happens during a stack underflow?

A

An attempt is made to pop an element from an empty stack.

53
Q

Fill in the blank: Stacks are often used in algorithms that require _____.

A

backtracking.

54
Q

What does a stack’s ‘top’ refer to?

A

The most recently added element that is available for removal.