Data Structures Flashcards
What does the acronym LIFO mean?
Last In First Out
Can refer to data structures that limit interaction to a single end. The last value pushed into the data structure is the first value popped out of it.
What methods are available on a Stack data structure?
.push(value) - adds a value to the top of the stack
.pop( ) - returns the top value in the stack and removes it
.peek( ) - returns the top value in the stack without removing
What must you do the access the value at an arbitrary point in a stack (not just the “top”)?
If the stack can be mutated: call pop( ) on the stack the necessary amount of times
No mutation: call pop( ) on the stack and store all the values in an array. Get the desired value then push the values from the array back onto the stack in reverse order
What does the acronym FIFO mean?
First In First Out
The first thing enqueued into a stack is the first thing out. Head of the structure is processed first
What methods are available on a Queue data structure?
.enqueue(value) - adds a value to the end of the queue
.dequeue( ) - removes and returns the value at the start of the queue
What must you do to access the value at an arbitrary point in a queue (not just the “front”)?
Must cycle through the queue the amount of times necessary while dequeueing and enqueueing the first item
How are linked lists different from an array?
Can’t access arbitrary nodes.
Can only traverse them in one direction
How would you access an arbitrary node in a linked list (not just the “head”)?
Have to go down the list of nodes the number of times desired and get the data from that node