Time complexity is a way to describe how long an algorithm takes to run as the input size grows.
Common time complexities:
- O(n): If you check each name one by one, that’s called linear time complexity, or O(n). As the list gets longer, the time to find a name grows linearly.
- O(log n): Even as the list gets much longer, the search time doesn’t increase as much.
- O(1): The list size doesn’t affect how long it takes.
- O(n^2): As input size increases, running time increases quadratically. Common in simple sorting algorithms like bubble sortor insertion sort.
- O(n log n): Linearithmic time. Often seen in efficient sorting algorithms like mergesort and quicksort. It’s more efficient than O(n^2) for large datasets.
- O(2^n) - Exponential time
- O(n!) - Factorial time: