Lecture 008

divide and conquer: divide in half, solve problem in small, put together big solution.

Merge Function

Fast Sorting Algorithms

Merge sort

Cost:

Merge Sort cost

Merge Sort cost

Recursive Safety

Quick sort

Partition

Partition

Quick sort condition

Quick sort condition

Partition Complexity

Partition Complexity

Partition Complexity

Partition Complexity

How to pick pivot:

  1. pick A[lo]
  2. random pick A[i]
  3. pick 3 number and compare them

Stable Sorting

Best case complexity

Selection Sorting Merge Sort Quick Sort
Worst Case n^2 n log(n) n^2
Average Case n^2 n log(n) n log(n)
Best Case n^2 n log(n) n log(n)
In-Place Y N Y
Stable N Y Y

stable: whether sort among 2 dimension produce the same outcome

Searching and Sorting Complexity Chart

Searching and Sorting Complexity Chart

Math Graph

Math Graph

Table of Content