Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modals/InfoModals.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Modals = {
<li>The best case is when we have a sorted array (terminates if no swaps are made)</li>
<li>
The worst case is when we have a reverse sorted array (we perform&nbsp;
<span className="equation">n + (n - 1) + (n - 2) + ... = n²</span>&nbsp;comparisons)
<span className="equation">(n - 1) + (n - 2) + ... + 1 = n(n - 1) / 2 = O(n²)</span>
</li>
</ul>
),
Expand Down
6 changes: 3 additions & 3 deletions src/pseudocode.json
Original file line number Diff line number Diff line change
Expand Up @@ -1433,11 +1433,11 @@
"find": {
"code": [
["procedure BubbleSort(array):"],
[" end ← array.length"],
[" end ← array.length - 1"],
[" start ← 0"],
[" while start < end:"],
[" swapped ← start"],
[" for j ← 0, end:"],
[" for j ← start, end - 1:"],
[" if array[j] > array[j + 1]:"],
[" swap array[j], array[j + 1]"],
[" swapped ← j"],
Expand All @@ -1453,7 +1453,7 @@
[" start points to first element"],
[" while (start < end):"],
[" lastSwapped points to start"],
[" for (j from start to end):"],
[" for (j from start to end - 1):"],
[" if (array[j] > array[j + 1]):"],
[" bubble array[j] by swapping up"],
[" lastSwapped points to j"],
Expand Down
2 changes: 1 addition & 1 deletion src/time_complexities.json
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@
"BubbleSort without Last Swap Optimization": {
"worst": {
"big_o": "O(n²)",
"explanation": "We compare every element to every other element, which is approximately $n$ times $n$ work.",
"explanation": "BubbleSort repeatedly compares adjacent elements, resulting in O(n²) time complexity.",
"example": "[5, 4, 3, 2, 1]"
},
"average": {
Expand Down