Stack Flashcards

1
Q

Is an Stack Random or Sequential Access?

A

Sequential

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

A stack is a data structure in which we add elements and remove elements according to LIFO or FIFO?

A

LIFO. Last in, First out.

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

What is a real world analogy for a Stack?

A

Washing a stack of dishes. When someone adds a plate to the stack, it will be the first one you grab to wash.

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

What does BigO scoring not account for with the stack?

A

It’s useful LIFO ability.

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

What are the four fairly standard Stack methods?

A

Push, Pop, Peek and Contains.

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

How should you implement a Stack in Kotlin?

A

Use java.util.ArrayDeque.
E.g.
var stack = ArrayDeque()

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

How should you NOT implement a Stack in Kotlin?

A

You should NOT use java.util.Stack.

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

What does the PUSH method do?

A

It pushes an element onto the top of the Stack.

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

What does the POP method do?

A

It removes an element form the top of the stack and return the ‘popped’ element.

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

What does the PEAK method do?

A

It allows you to get the value at the top of the list without actually removing it.

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

What does the CONTAINS method do?

A

It is used for searching through the Stack. It returns true or false.

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

What is the BigO of ACCESSING an element in a Stack?

A

O(n) Worst-case the element we need is at the bottom of the stack and we must pop all other elements on top of it before reaching the bottom element.

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

What is the BigO of SEARCHING an element in a Stack?

A

O(n) Linear Search is required.

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

What is the BigO of INSERTING an element in a Stack?

A

O(1) Push requires only one operation.

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

What is the BigO of DELETING an element in a Stack?

A

O(1) Pop requires only one operation.

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

What is an example use case of a Stack

A

Recursion. Each time a function calls itself it is pushed to the stack and then popped when it completes.
Back button in a web browser.
Undo/Redo.