Week 1 stack Flashcards

(27 cards)

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

Define stack in data structures.

A

A linear 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
3
Q

What is the top of a stack?

A

The most recently added element in the stack.

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

True or false: A stack allows insertion and deletion at both ends.

A

FALSE

A stack only allows operations at one end.

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

Fill in the blank: The push operation adds an item to the ______.

A

top of the stack.

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

What does the pop operation do?

A

Removes the top element from the stack.

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

Define peek in the context of stacks.

A

Retrieves the top element without removing it.

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

What is a stack overflow?

A

An error that occurs when too many elements are added to a stack.

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

True or false: Stacks 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 is the size of a stack?

A

The number of elements currently stored in the stack.

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

Fill in the blank: The empty operation checks if the stack is ______.

A

empty.

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

What is the time complexity of push and pop operations?

A

Both operations have a time complexity of O(1).

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

Define stack underflow.

A

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

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

What is the main use of stacks?

A

To manage function calls and maintain execution order.

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

True or false: Stacks are used in depth-first search algorithms.

A

TRUE

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

Fill in the blank: In a stack, the last element added is the first to be ______.

17
Q

What is a stack frame?

A

A section of the stack that contains function call information.

18
Q

Define dynamic stack.

A

A stack that can grow and shrink in size during runtime.

19
Q

What is the main difference between a stack and a queue?

A

A stack uses LIFO while a queue uses FIFO.

20
Q

True or false: Stacks can be used to reverse strings.

21
Q

Fill in the blank: The base of a stack is where ______.

A

the first element is added.

22
Q

What is a bounded stack?

A

A stack with a fixed maximum size.

23
Q

Define stack data structure in one sentence.

A

A collection of elements with restricted access to the last added item.

24
Q

What is the push operation’s time complexity?

A

O(1), as it adds an element directly to the top.

25
What is the **pop** operation's time complexity?
O(1), as it removes the top element directly.
26
True or false: You can access elements in a stack randomly.
FALSE ## Footnote Elements can only be accessed from the top.
27
What is the **main advantage** of using a stack?
It provides a simple way to manage data in a last-in-first-out manner.