Lecture 29: Basic Sorts

11/4/2020

Sorting Definitions

Java Note

import java.util.Comparator; public class LengthComparator implements Comparator<String> { public int compare(String x, String b) { return x.length() - b.length(); } }

Sorting: An Alternate Viewpoint

Performance Definitions

Selection Sort and Heapsort

Selection Sort

Naive Heapsort: Leveraging a Max-Oriented Heap

In-place Heapsort

Mergesort

Mergesort

Insertion Sort

Insertion Sort

In-place Insertion Sort

Observation: Insertion Sort on Almost Sorted Arrays

Insertion Sort Sweet Spots

Sorts Table