- Linear Data Structures
- Array
- Linked List
- Stack
- Queue
- Non-Linear Data Structures
- Graph
- Tree
Search | Best case | Average case | Worst case |
---|---|---|---|
Linear search | |||
Binary search |
Explanation and code examples can be found here
Hashing is the process of mapping a search key to a limited range of available array indices (positions), referred to as slots (buckets), with the goal of providing direct access to the keys.
Hash Function: a function that maps a key to the slot where that item belongs in the hash table. Putting a hash function and an array together, we can build a data structure called a Hash Table.
Hash Table: a data collection that stores pairs of keys and values, designed to enable quick retrieval of values by their associated keys.
Slot (Bucket): a unique position in a hash table, capable of holding one or more items, which are mapped to it via their keys.
- Division: key % table_size
- Multiply-Add-and-Divide(MAD): ((a*key + b) % p) % m
- Truncation: ignore some columns in the key, and use the rest to compute the hash values.
- Folding: split a key into multiple parts and combine them into a single integer by adding them.
- Hashing Strings: summing the ASCII values of the individual characters.
- Optimizing by making the best choice at the moment
- Does not always find the optimal solution, but it is fast.
- May require almost no memory
- Example: Dijkstra's Algorithm
- Optimizes by breaking down the problem into subproblems, typically using recursion to solve the problem.
- Finds the optimal solution, but is slower than Greedy Algorithms.
- May require some memory.
- Example: Merge sort
- Optimizes by caching the answers to each subproblem as not to repeat the calculation.
- Finds the optimal solution, but may be pointless to use on small data.
- May require a lot of memory.
- Example: memoized fibonacci.
Class relationship examples can be found here
Common big-O functions listed from smallest to largest order of magnitude
Common name | |
---|---|
constant | |
logarithmic | |
linear | |
log linear | |
quadratic | |
cubic | |
exponential |
- Program spends most of its time accessing slow devices, like a network connection, a hard drive, or a printer.
- Speeding it up involves overlapping the times spent when waiting for these devices.
- Multihreading recommended
- Program spends most of its time doing CPU operations.
- Speeding it up involves finding ways to do more computations at the same amount of time.
- Multiprocessing recommended.