From fe51b5eaa750268ea17e98168f3e5322009cc756 Mon Sep 17 00:00:00 2001 From: Carlos Navarrete Date: Mon, 26 Feb 2024 15:33:32 -0700 Subject: [PATCH] Update bubble-sort.md Just a typo in there, it seems. --- lessons/bubble-sort.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lessons/bubble-sort.md b/lessons/bubble-sort.md index 26dfc16..ac8e90b 100644 --- a/lessons/bubble-sort.md +++ b/lessons/bubble-sort.md @@ -64,7 +64,7 @@ What is the absolute best, ideal case for this algorithm? A sorted list. It'd ru What is the absolute worst case scenario? It'd be a backwards sorted list. Then it'd have to run all comparisons and always swap. Assuming we did the optimized version above, that'd be 4 comparisons and swaps on the first go-around, then 3, then 2, then 1, totalling 10 comparisons and swaps. This will grow exponentially as the list gets bigger. This would be O(n²). -Okay, so average case. You can think of average case as "what happens if we through a randomly sorted list at this". For our bubble sort, it'd be like the one we did above: some numbers in order, some not. What happens if we through 10 at it versus 1000. The amount of comparisons and swaps would grow exponentially. As such, we'd say it's O(n²) as well. +Okay, so average case. You can think of average case as "what happens if we through a randomly sorted list at this". For our bubble sort, it'd be like the one we did above: some numbers in order, some not. What happens if we throw 10 at it versus 1000. The amount of comparisons and swaps would grow exponentially. As such, we'd say it's O(n²) as well. What about the spatial complexity? In our case, we're operating on the array itself and not creating anything else in memory, so the spatial complexity of this is O(1) since it'd never grow. Because we are operating on the array itself, we'd say this sort is **destructive**. What if you needed to keep the original array in addition to the sorted one? You couldn't use this sorting method or you'd have to pre-emptively make a copy. Other sorting algorithms are non-destructive.