Introduction
Imagine you want to know how long a task will take as the size of the input grows. Time complexity helps us understand how the time needed changes when we handle bigger problems.
Imagine sorting a deck of cards. If you have just a few cards, sorting is quick. But if you have hundreds, some ways of sorting take much longer than others. Time complexity is like knowing how your sorting time grows as you add more cards.
┌───────────────┐
│ Input Size n │
└──────┬────────┘
│
▼
┌─────────────────────────┐
│ Time Complexity Growth │
│ │
│ O(1) ──┐ │
│ O(log n)│ │
│ O(n) │ │
│ O(n²) │ │
└────────┴───────────────┘def linear_search(arr, target): for i in range(len(arr)): if arr[i] == target: return i return -1 print(linear_search([1, 3, 5, 7, 9], 7))