Python (Fall 2026) Module 9-2: Creating a Sorting Algorithm
Watch on YouTube →
Overview
Bill Moseley explains algorithms as repeatable step-by-step procedures, then develops a selection sort by repeatedly finding the smallest remaining value and moving it to a separate list. His Python example scans a list, tracks the minimum with `intLow`, appends it to `liSorted`, and removes it from the original list until empty; the approach handles duplicates and generalizes across list sizes, provided the initial minimum value is sufficiently large.
Key takeaways
- An algorithm is a repeatable step-by-step procedure that can solve many instances of the same problem, as illustrated by multi-digit multiplication.
- Selection sort finds the smallest value still unsorted, transfers it to the output, and repeats until no values remain.
- In the Python implementation, `intLow` tracks the current minimum during a scan of `liNum`, while `liSorted` collects values in ascending order.
- `list.remove(value)` is appropriate when deleting the selected minimum by its value; `list.pop()` instead removes an item by index.
- The implementation can sort duplicate values, but its initial `intLow` sentinel must be larger than every input value or replaced with a safer approach.
Chapters
- Multi-digit multiplication follows the same sequence of steps regardless of which numbers are being multiplied.
- A procedure that works across different inputs is an algorithm: a step-by-step method for solving a problem.
- Many simple operations can make a large calculation error-prone, illustrating why consistent procedures matter.
- To sort number cards in ascending order, scan the remaining cards, keep track of the lowest value, and move it to a separate stack.
- Repeat the scan and transfer until every card has been removed from the unsorted group.
- The same selection process applies when the card values are stored in a Python list rather than laid out physically.
- Use `while len(liNum) > 0` to repeat the selection process until the original list is empty.
- Scan each `intNum` in `liNum`, updating `intLow` whenever a smaller value is found; initialize `intLow` above all possible values, such as 1,000 for the example's range.
- Append the minimum with `liSorted.append(intLow)` and remove that value with `liNum.remove(intLow)`; `remove` takes a value, unlike `pop`, which uses an index.
- The demonstrated sort handles duplicate values and different list sizes; choosing a sufficiently large initial minimum avoids limiting valid inputs to numbers below 1,000.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.