Stacks Flashcards

Learn about what a stack is and what stack overflows are

1
Q

What is a stack overflow?

A

A stack overflow is an error that occurs when a program exceeds the maximum amount of memory that is allocated for its execution.

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 a data structure that can hold many elements.

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

How are elements organised in a stack?

A

LIFO - Last in first out

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

What are the operations you can do on a stack?

A
  • push()
  • pop()
  • peek()
  • isEmpty()
  • size()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the two ways you can implement stacks?

A

Arrays and linked lists.

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

What can stacks be used for?

A

Implementing undo mechanisms, revert to previous states, create algorithms, performing depth-first searches in graphs and backtracking.

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

What does pop() do?

A

Removes and returns the top element from the stack.

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

What does push() do?

A

Adds a new element to the stack.

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

What does peek() do?

A

Returns the top element from the stack.

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

What does isEmpty() do?

A

Checks if the stack is empty.

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

What does size() do?

A

Finds the number of elements in the stack.

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

What are some reasons to implement stacks using arrays?

A

Memory Efficient - Array elements do not hold the next elements address like linked lists and nodes do.

Easier to implement and understand - Using arrays to implement stacks requires less code than using linked lists, and for this reason it is typically easier to understand as well.

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