Data Structures Flashcards
What does the acronym LIFO mean?
Last in first out - The last thing pushed onto the stack is the first thing that can be popped out
What methods are available on a Stack data structure?
- push(value) - adds a value to the “top” of the stack
- pop() - removes the top value from the stack and returns it
- peek(), which returns the “top” value of the stack without removing it.
What must you do to access the value at an arbitrary point in a stack (not just the “top”)?
You pop everything off until you get to where you want, and then you push everything back
What does the acronym FIFO mean?
first-in-first-out (FIFO) operations: the first thing enqueued onto the queue is the first thing that can be dequeued out.
What methods are available on a Queue data structure?
- enqueue(value) - adds a value to the “back” of the queue
- dequeue() - removes the “front” value from the queue and returns it
- peek(), which returns the “front” value of the queue without removing it.
What must you do to access the value at an arbitrary point in a queue (not just the “front”)?
Dequeue everything until you get to where you want, and then enqueue those values back
How are linked lists different from an array?
Linked lists are sequential access (like a queue), not random access (like an array). That means that, in order to go to a specific place in the list, you have to start at the beginning, then jump from node to node until you get there. However, unlike a queue, a linked list doesn’t need to be mutated to scan its contents.
How would you access an arbitrary node in a linked list (not just the “head”)?
In a basic linked list, you start at the “head” node, then jump to the next node through the .next property. The last node in a basic linked list is called the “tail” node. The “list” itself is simply a reference to the “head” node. Since each node only contains a reference to the next node in the list, there is no way to backtrack. That means each node is the “head” of its own list, and there’s no way to tell if any other nodes came before it.*
What properties are available on linked lists?
.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.