CS 411 Fall 2025  >  Outline & Supplemental Notes for September 10, 2025


CS 411 Fall 2025
Outline & Supplemental Notes
for September 10, 2025

Outline

Algorithmic Strategies, Brute Force, Exhaustive Search [L Ch 3 intro]

Simple Brute-Force Methods [L 3.1–3.2]

Supplemental Notes

Relative Advantages of Selection Sort vs. Bubble Sort

The text notes that Selection Sort uses only only \(\Theta(n)\) swaps when sorting a list of \(n\) items. This compares favorably with most other sorting algorithms. It is certainly better than Bubble Sort, which does \(\Theta(n^2)\) swaps. However, this is not the whole story.

  Selection Sort Bubble Sort
Without Optimization
Bubble Sort
With Optimization
Comparisons \(\Theta(n^2)\) \(\Theta(n^2)\) \(\Theta(n^2)\)
Swaps \(\Theta(n)\) \(\Theta(n^2)\) \(\Theta(n^2)\)
Stable? No Yes Yes
Operations performed
when each item is
close to final position
As above As above \(\Theta(n)\) comparisons
\(\Theta(n)\) swaps

Above, “close” means that each item’s initial location is within some constant distance of its eventual spot in the sorted list. We require that every such distance is at most this fixed limit, no matter how large \(n\) may be.

Stability is a very important consideration. If we need a stable sort, then an unstable algorithm is simply unacceptable, no matter how efficient it may be.

Regardless, it should be noted that the appropriate time to use Selection Sort or Bubble Sort is NEVER. It is true that, in the special case of a dataset in which each item is known to be close to its place in the sorted list, an optimized Bubble Sort is linear time—faster than Merge Sort and Heap Sort! However, even then, Insertion Sort would generally be the algorithm of choice.