data-structures-stacks Flashcards

1
Q

What does the acronym LIFO mean?

A

last-in-first-out (LIFO) operations: the last thing pushed onto the stack is the first thing that can be popped out.

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

What methods are available on a Stack data structure?

A

.push(value) - adds a value to the “top” of the stack

.pop() - removes the top value from the stack and returns it

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

What must you do to access the value at an arbitrary point in a stack (not just the “top”)?

A

you would pop the top values from the stack into an empty array until the value that is looked for is now at the top of the stack , use the peek method of the stack object and the result of that will be pushed into a second empty array. The previously popped values that now populates the first empty array are then pushed back into the stack, and the second empty array with the value retrieved from the peek method is returned..

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

What does the acronym FIFO mean?

A

first-in-first-out, the first thing enqueued onto the queue is the first thing that can be dequeued out.

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

What methods are available on a Queue data structure?

A

enqueue(value) - adds a value to the “back” of the queue

dequeue() - removes the “front” value from the queue and returns it

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

What must you do to access the value at an arbitrary point in a queue (not just the “front”)?

A

Take stuff off of the front until value is on top.

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

How are linked lists different from an array?

A

Linked lists are sequential access (like a queue), not random access (like an array).

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

How would you access an arbitrary node in a linked list (not just the “head”)?

A

.data - contains the node’s value.
.next a reference to the next node in the list, if there is one. If there is no “next” node in the list, this property is typically set to null.

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

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

defined

In JavaScript, closures are created every time a function is created, at function creation time.

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

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

the return of calling another function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
What does this code do?
const wrap = value => () => value;
A
const wrap = function(value){
return function(){
return value
}
}

defines a function that returns another function that returns the value

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

const wrap = value => () => value

A

const hold34 =wrap(34)

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