loading
Code Bits
Visualize algorithm complexity with interactive D3.js charts. Understand how different time complexities scale.
If each operation takes 1μs:
Executes in the same time regardless of input size. Array access, hash table lookup.
return arr[0];Halves the problem space each step. Binary search, balanced tree operations.
while (n > 1) n = n / 2;Time grows proportionally with input. Single loop through data.
for (i = 0; i < n; i++)Efficient sorting algorithms. Merge sort, quicksort average case.
mergeSort(arr)Nested loops over data. Bubble sort, comparing all pairs.
for (i) for (j)Triple nested loops. Naive matrix multiplication.
for (i) for (j) for (k)Doubles with each input increase. Recursive Fibonacci, power set.
f(n-1) + f(n-2)function getFirst(arr) {
return arr[0]; // Direct access
}Accessing an array element by index takes constant time regardless of array size.
| Algorithm | Best | Average | Worst | Space |
|---|---|---|---|---|
| Binary Search | O(1) | O(log n) | O(log n) | O(1) |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) |
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) |
| Hash Table Lookup | O(1) | O(1) | O(n) | O(n) |
| BFS/DFS | O(V+E) | O(V+E) | O(V+E) | O(V) |