POST 1 of 5 MorningDSAConcept
Big-O isn't math. It's a label for growth.
Day 15. Week three. We pivot from Python the language to the algorithms and data structures Python the language sits on top of. Let's start with the question every interviewer asks and most candidates answer badly — 'what's the time complexity?' Big-O is not math. It's a label that describes how an algorithm's runtime (or memory) grows as the input size grows. That's it. The constants don't matter. The lower-order terms don't matter. We care about the growth pattern, not the exact count. The six classes you'll meet daily, in order of pain: O(1) — constant. Doesn't grow with input size. dict lookup. Array indexing. The fastest possible. O(log n) — logarithmic. Halves the input each step. Binary search. Tree depth in a balanced tree. Doubling input adds one step. Phenomenal scaling. O(n) — linear. Touches each item once. Scanning a list. Reading a file. Doubling input doubles the work. Acceptable. O(n log n) — linearithmic. Best general-purpose comparison sort. Mergesort, timsort, heapsort. Doubling input slightly more than doubles the work. Considered efficient. O(n²) — quadratic. Nested loop over the input. Bubble sort. Naive duplicate check with two for-loops. Doubling input quadruples the work. Painful past 10k elements. O(2ⁿ) — exponential. Recursive subset enumeration without memoisation. Each new input doubles the entire work. Painful past 30 elements. Almost always fixable with DP. You don't need to compute exact constants. You need to recognise which family your code falls into. That recognition, applied repeatedly, is the difference between code that scales and code that bricks production.
#DSA#DataStructures#Algorithms#Python#100DaysOfCode#BigO