Lesson 1 of 8Article18 minFREE
Introduction to DSA and Big-O Complexity
Data structures decide how data is stored and accessed; algorithms decide how operations are executed. The same problem can feel instant or painfully slow depending on these choices.
Why data structures and algorithms matter
Data structures decide how data is stored and accessed; algorithms decide how operations are executed. The same problem can feel instant or painfully slow depending on these choices.
In interviews and real systems, you are often evaluated on correctness first, then scalability: does your solution still work when input size grows from 100 to 10 million?
Big-O intuition
- O(1): constant time, independent of input size.
- O(log n): divide-and-conquer steps, like binary search.
- O(n): one full pass over data.
- O(n log n): efficient comparison sorting family.
- O(n^2): nested loops over same data, often too slow at scale.
Comparing linear vs binary search
function linearSearch(arr: number[], target: number): number {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === target) return i; // O(n)
}
return -1;
}
function binarySearch(sorted: number[], target: number): number {
let left = 0;
let right = sorted.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (sorted[mid] === target) return mid;
if (sorted[mid] < target) left = mid + 1;
else right = mid - 1;
}
return -1; // O(log n)
}