Big 0 Time Flashcards
Linear Time
O(n)
Constant Time
O(1)
Quadratic Time
O(n^2)
What scenario do we care about when measuring time complexity?
Worst case scenario/upper bound
Logarithmic Time
O(logn)
Traveling Salesman Time Complexity
O(n!)
Bubble Sort Time Complexity
O(n^2)
Insertion Sort Time Complexity
O(n^2)
Merge Sort Time Complexity
O(nlogn)
Quicksort Time Complexity
O(nlogn)
Binary Search Time Complexity
O(logn)
First Recurring Character in a string Time Complexity
O(n^2)
Rank the algorithms Rate of Increase for Big O
O(logn)>O(n)>O(nlogn)>O(n^2)>O(2^n)>O(n!)
When there is a function with multiple calls, the runtime will often be:
O(branches^depth)
Binary Tree Insert/find
O(logn)
Hash Table
constant time O(1)
Linked List
O(n)
Objects
Constant time for lookup/insert/removal, linear time for searching O(n)
Arrays
Access O(1), Searching O(n), Insertion/Removal depends on beginning or end
Binary Heap
Insert/Remove O(logn)
Graph: Adjacency Matrix vs List Edge Tradeoffs
List:
- Takes up less Space
- Faster iteration over edges
- Slower to query edge
Matrix:
- Takes up more space (in sparse graphs)
- Longer to iterate over edges
- Faster to query an edge