Name | Complexity |
---|---|
Selection sort | All case: |
Bubble Sort | All case: |
Shell sort | Worst: |
Early-termination Bubble sort | Best: Worst: Avg: |
Insertion sort | Best: Worst: Avg: |
Merge sort | All case: |
Quick sort | Best: Worst: Avg: Avg case 39% faster than merge sort |
Heap sort | Build + Deque |
DFS, BFS | Adj Matrix: Adj List: |
Binary search | Best: Worst: If the array is sorted or has access to any positon |
BST Search | Best: Average: Worst: If it’s a stick, that’s |
Search in sorted list | Merge sort + binary search Worth to presort when: |
AVL trees | Height: Search and Insert: Delete: Rebalance (rotations): Disadvantages: Rotations are frequent and implementation is complex |
2-3 trees | Height: SEARCH, INSERT, DELETE: Rebalancing: < |
Heaps | Height: Repair: C(n) = Building: |
Distribution sorting | Worst case: if Space: |
Hash tables | List - Insert: - Delete: - Search: Balance Tree - Insert: - Delete: - Search: Array - Insert: - Delete: - Search: Open Hashing - Insert: - Delete: propotional to list’s length - Search: propotional to list’s length - Average: |
Prim’s algorithm | Min-heap + Adjacency list - Fibonacci heap + adjacency list - |
Kruskal’s algorithm | If there are edges: - If there is no edge: - |
Dijkstra’s Algorithm | Min-heap: - |
Huffman’s Code | Min-heap: - Sorted by probabilities: - |
Edit distance | Worse and Average: - Construction: where n and m is length of 2 strings. - Backtrace complexity: |
Knapsnack problem | Build table: Backtrace complexity: |
Warshall’s algorithm | Complexity: Space: DFS & BFS: for n, for 1 If not many: |
Stack:
Add and remove at front.
All log
, ln
has the same speed
(n-1)! < n!
When rotating for AVL trees. If one element changes its position to the right. We say R(that element). So draw first and then write rotation direction.