Time/Space Complexity Flashcards
O(1)
Constant time. Most efficient algo
Big O of pop/remove from hashmap
O(1)
Big O of lookup in hashmap
O(1)
Big O of search an array
Worse case: O(n)
Might have to go through entire array to find
Big O of insert into hashmap
O(1)
Big O of loop through an array
O(n)
Big O of push/pop from array
O(1)
What is O(log n)
Binary search.
On every iteration of loop, we halve the remaining elements and search again
What is O(n^3)
3-D data structure. Get triplets of loops
What is O(n * m)
2-D array that’s not a perfect square (ex. 2x3 grid)
Big O of getting length of list
O(1)
Big O deque vs. list
Index access:
- Deque: O(n)
- List: O(1)
Pop from right:
- Deque: O(1)
- List O(1)
Pop from left:
- Deque: O(1)
- List: O(n)
Big O of sum an array
O(n)
What is O(n!)
Permutations
Ex. traveling salesman
What is O(n log n)
Heap sort, merge sort