Practice Sorting in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

Rearranging items in a collection into a defined order, such as smallest to largest or alphabetical.

Putting things in order—alphabetical, numerical, by date—so they are easier to find and use.

Example 1

medium
Sort the list [5, 2, 8, 1, 9] using bubble sort. Show the first two passes.

Example 2

hard
Compare bubble sort and merge sort in terms of time complexity. When would you choose one over the other?

Example 3

medium
Sort [4, 1, 3] using insertion sort. Show each step.

Example 4

medium
You have a list of exam scores that is already sorted except one new score was added at the end. Would insertion sort or bubble sort be a better choice, and why?