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]
- Start of new section of course: 8 algorithmic strategies.
- Brute force
- Definition: straightforward approach, often directly based on problem statement & definitions.
- Why we study: widely applicable method, and as a baseline for other strategies.
- Exhaustive search
- Closely related to brute force.
- Definition: Look at all parts of a solution space.
- Why we study: When doing a brute-force approach to a problem with a complicated solution space, it may not be obvious how to look at all possible solutions.
Simple Brute-Force Methods [L 3.1–3.2]
- The Sorting Problem
- Selection Sort
- Bubble Sort
- Relative advantages of Selection Sort vs. Bubble Sort
- Searching
- Sequential Search
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.