diff --git a/lessons/bubble-sort.md b/lessons/bubble-sort.md index 26dfc16..3a67a54 100644 --- a/lessons/bubble-sort.md +++ b/lessons/bubble-sort.md @@ -52,9 +52,9 @@ End of the array, did we swap anything? No. List is sorted. That's it! -So, one more fun trick. Eventually, on your first runthrough, you will find the biggest number and will continue swapping with it until it reaches the last element in the array (like we did with 5 in our example.) This is why it's called bubble sort: the biggest elements bubble to the last spots. Thinking about this for a second, that means at the end of the iteration we're guaranteed to have the biggest element at the last spot. At the end of our first iteration above, 5 is the last element in the array. That means the last element in the array is definitely at its correct spot. That part of the array is sorted. So, on our second run through of the array, we technically don't need to ask `Are 4 and 5 out of order? No.` because know ahead of time that 5 is going to be bigger no matter what. So we can check one less element each iteration because we know at the end of each iteration we have one more guaranteed element to be in its correct. At the end of the second iteration we'll have 4 in its correct place, then 3, then 2, etc. +So, one more fun trick. Eventually, on your first runthrough, you will find the biggest number and will continue swapping with it until it reaches the last element in the array (like we did with 5 in our example.) This is why it's called bubble sort: the biggest elements bubble to the last spots. Thinking about this for a second, that means at the end of the iteration we're guaranteed to have the biggest element at the last spot. At the end of our first iteration above, 5 is the last element in the array. That means the last element in the array is definitely at its correct spot. That part of the array is sorted. So, on our second run through of the array, we technically don't need to ask `Are 4 and 5 out of order? No.` because know ahead of time that 5 is going to be bigger no matter what. So we can check one less element each iteration because we know at the end of each iteration we have one more guaranteed element to be in its correct spot. At the end of the second iteration we'll have 4 in its correct spot, then 3, then 2, etc. -It's a little optimization (in our Big O it'd affect the coefficient so it'd wouldn't reflected in the Big O.) but it does make it a bit faster. It makes the sorting go faster as algorithm progresses. +It's a little optimization (in our Big O it'd affect the coefficient so it wouldn't be reflected in the Big O.) but it does make it a bit faster. It makes the sorting go faster as the algorithm progresses. ## Big O