Stacks Flashcards

1
Q

What type of data structure is a stack?

A

Its a LIFO, which means last in first out.

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

What are the use cases for a stack?

A

1 - Managing function calls
2 - Undo / Re Do Functionalities
3 - Routing
4 - Used with other algorithms

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

What are two ways to implement a stack?

A

Using a array or a singly linked list.

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

Using an array, how would we implement a stack?

A

To implement a stack using arrays in JavaScript, you can use the push and pop methods.

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

Why would we not use shift and unshift when when implementing a stack with an array?

A

These methods will result in worse Big O notation. This is because every time we add or remove from the beginning, we have to re-index everything.

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

How would you implement a stack with a singly linked list?

Implement it.

A

Add and remove from the beginning of the list instead of the end.

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

When should you use stacks?

A

When you need to do inserting and removal operations.

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

When should you not use stacks?

A

When you need to do searching and accessing.

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

What is the Big O of insertion and removal for stacks?

A

Both are O(1).

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