An Array is a fundamental linear data structure that stores collection of elements sequentially in contiguous memory locations. Because memory addresses are calculated directly via index math, accessing any item takes instant constant time $O(1)$.
array[i] is $O(1)$.Click on any card below to open its dedicated deep-dive theory sheet with step-by-step code and execution details:
Repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
Divide-and-conquer algorithm that selects a 'pivot' element and partitions the array around it.
Builds the sorted array one item at a time. Extremely efficient for small or nearly-sorted datasets.
Recursively splits array in halves, sorts each half, and merges them back together predictably.
Here is a summary of theoretical performance, space complexity, and properties across different algorithms:
| Algorithm | Best Time | Average Time | Worst Time | Space | Stable? | In-Place? |
|---|---|---|---|---|---|---|
| Bubble Sort | $O(n)$ | $O(n^2)$ | $O(n^2)$ | $O(1)$ | Yes | Yes |
| Insertion Sort | $O(n)$ | $O(n^2)$ | $O(n^2)$ | $O(1)$ | Yes | Yes |
| Quick Sort | $O(n \log n)$ | $O(n \log n)$ | $O(n^2)$ | $O(\log n)$ | No | Yes |
| Merge Sort | $O(n \log n)$ | $O(n \log n)$ | $O(n \log n)$ | $O(n)$ | Yes | No |