Bubble Sort
We certainly like it when things are organized. Having data assembled in a particular order makes it substantially easier to glean information from that data; for example, having all the test scores for a classroom of students makes it easy to figure out where the median score lies if and only if those test scores are arranged in a sorted order. But data rarely arrives in a sorted order. In this section, you will start to consider what sorting is and what the costs of sorting data might be as well as a basic approach to sorting that narrows the scope of our problem to focusing on ordering just two elements at a time, instead of an entire array at a time. This approach is very straightforward, but possibly at the expense of making an inordinate number of swaps just to put one single element into position.
-
Lecture (Part 0)
-
Lecture (Part 1)
-
Shorts
-
Notes
-
Thought Questions
- Why is sorting data useful?
- Why does it matter what method we use to sort our data?
- What makes bubble sort an effective sort? What makes it ineffective?
- Why might we decide to keep track of how many swaps we have made on each pass through the array?