Python 3D Academyবাংলা

Simple Sorts in Python

Chapter 44: Simple Sorts

4 short lessons, with 3D animations, quizzes and coding tasks.

The lessons

  1. Why sorting matters, and bubble sort

    Bubble sort walks the list again and again, swapping any two neighbours that are in the wrong order, and each walk carries the biggest value still out of place to the end.

  2. Selection sort and insertion sort

    Selection sort repeatedly finds the smallest value of the unsorted part and swaps it to that part's front; insertion sort takes the next value and slides it left into its place among the values already sorted.

  3. Stability and sort keys

    A sort is stable when values that compare equal keep the order they had before sorting, and a sort key is the part of each item the sort compares.

  4. Comparing the simple sorts: best and worst cases, counted

    Compare sorts by counting their comparisons and swaps on the inputs that are best and worst for each, because a sort's cost depends on how out of order its input is.