You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/02-foundamental-problem-domains/01-sorting.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,7 +124,7 @@ public void bubbleSort(int[] elements) {
124
124
***The Inefficiency:** The standard implementation is completely blind to the state of the data[cite: 158]. Even if the array becomes perfectly sorted on the very first pass, the outer loop stubbornly forces the inner loop to continue executing all subsequent passes, repeating redundant comparisons across already ordered sequences[cite: 158].
125
125
***Asymptotic Profile:** $O(n^2)$ across **all** cases (Best, Worst, and Average)[cite: 153, 154, 155]. It suffers from an extremely high volume of memory interchanges and comparisons[cite: 156, 157].
@@ -152,7 +152,7 @@ public void bubbleSortWithSentinel(int[] elements) {
152
152
***Best Case Improvement:** If given an array that is already completely sorted, the algorithm executes the inner loop exactly once, performs $n-1$ comparisons, detects zero changes, and terminates[cite: 160]. This drops the Best Case complexity down to a perfectly linear **$O(n)$**[cite: 238].
153
153
***Worst/Average Case:** If the array is inversely sorted, the sentinel provides zero benefit[cite: 239, 240]. The algorithm continues to scale quadratically at **$O(n^2)$**[cite: 239, 240].
@@ -180,7 +180,7 @@ public void insertionSort(int[] elements) {
180
180
***Operational Profile:** Best Case is **$O(n)$** when the input is pre-sorted[cite: 432]. Worst and Average cases scale quadratically at **$O(n^2)$**[cite: 433, 434].
181
181
***Mechanical Efficiency:** Although it shares the quadratic complexity class with Bubble Sort, Insertion Sort is substantially more efficient in absolute terms[cite: 436]. Instead of executing expensive three-step pointer swaps via `interchange()`, it utilizes a single variable holder (`pivot`) and performs fast, single-step memory shifts[cite: 436]. It performs significantly fewer raw read/write operations[cite: 436].
@@ -201,7 +201,7 @@ public void selectionSort(int[] elements) {
201
201
***The Predictability Asset:** Direct Selection is entirely deterministic and predictable[cite: 547]. Its comparison loop depends strictly on the size $n$ of the array, meaning it executes exactly $\frac{n(n-1)}{2}$ comparisons regardless of whether the initial input data was sorted, random, or inverted[cite: 547, 548]. Its complexity remains locked at **$O(n^2)$** across all execution states[cite: 543, 544, 545].
202
202
***The Exchange Advantage:** Because it isolates the absolute lowest element *before* executing a swap, it performs a maximum of exactly $n-1$ interchanges[cite: 546]. This exceptionally low volume of memory operations makes Selection Sort highly valuable on legacy embedded systems or flash hardware where writing bytes to memory is vastly more expensive or damaging than reading them[cite: 28, 546].
Copy file name to clipboardExpand all lines: concepts/03-algorithm-design-paradigms/04-dynamic-programming.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ public long fibonacciDV(int n) {
67
67
***Time Complexity:** Exponential, bounded between $O(2^{n/2})$ and $O(2^n)$.
68
68
***System Impact:** Evaluating $n = 50$ requires days of continuous processing because the runtime tree duplicates billions of identical state computations.
@@ -93,7 +93,7 @@ public long fibonacciPD(int n) {
93
93
***Space Complexity:****$O(n)$** to maintain the structural state table (which can be optimized down to $O(1)$ space by tracking only the two preceding states in scalar variables).
94
94
***System Impact:** Computes $n = 50$ and far beyond instantaneously in microseconds.
0 commit comments