Data Structures Flashcards
Hash Table
A hash table is a data structure that maps keys to values for highly efficient lookup.
Linked List
A data structure that represents a sequence of nodes
Singly Linked List
Each node points to the next node in the linked list
Doubly Linked List
Gives each node pointers to both the next node and the previous node
Runner Technique
The “runner” (or second pointer) technique is used in many linked list problems. The runner technique means that you iterate through the linked list with two pointers simultaneously, with one ahead of the other.
The “fast” node might be ahead by a fixed amount, or it might be hopping multiple nodes for each one node that the “slow” node iterates through.
Stack
Stack uses LIFO (last-in first out) ordering; most recent item added to the stack is the first item to be removed.
Stack Operations
pop(): remove the top item from the stack
push(item): add an item to the top of the stack
peek(): return the top of the stack
isEmpty(): return true if and only if the stack is empty
Stack offer constant-time access to the ith item?
False. Unlike an array.
Stack Constant time for add / remove
True. Constant time for push and remove. Does not require shifting elements around (unlike an array)
Queue
A queue implements FIFO (first-in first-out) ordering; items are removed from the data structure in the same order that they are added.
Queue Operations
add(item): add an item to the end of the queue
remove(): remove the first item in the queue
peek(): return the top of the queue
isEmpty(): return true if and only if the queue is empty
Trees
A tree is a data structure composed of nodes:
- Each tree has a root node
- Root node has zero or more child nodes
- each child node has zero or more child nodes, and so on
The tree cannot contain cycles. The nodes may or may not be in a particular order, they could have any data type as values, and they may not have links back to their parent nodes
True
Binary Trees
a binary tree is a tree in which the node has up to two children. Not all trees are binary trees.
Node “leaf”
A node is called a “leaf” node if it has no children