CS 4102: Algorithms

60
CS 4102: Algorithms Lecture 10: Linear Time Sorting David Wu Fall 2019

Transcript of CS 4102: Algorithms

Page 1: CS 4102: Algorithms

CS 4102: AlgorithmsLecture 10: Linear Time Sorting

David WuFall 2019

Page 2: CS 4102: Algorithms

2

Spring 2019 Warm Up

Show that finding the minimum of an unordered list requires Ω(𝑛) comparisons

Page 3: CS 4102: Algorithms

Lower Bound Proof for Finding the Minimum

Show that finding the minimum of an unordered list requires Ω(𝑛) comparisons

3

Suppose (toward contradiction) that there is an algorithm for that does fewer than ⁄𝑛 2 = Ω(𝑛) comparisons.

This means there is at least one element that was not looked atWe have no information on whether this element is the minimum or not!

2 8 19 20 3 9 -4

0 1 2 3 4 5 6 7

Page 4: CS 4102: Algorithms

Today’s Keywords

Sorting algorithmsLinear-time sorting algorithmsCounting sortRadix sortMaximum sum continuous subarray

4

CLRS Readings: Chapter 8

Page 5: CS 4102: Algorithms

Homework

• HW3 due Tuesday, October 1, 11pm• Divide and conquer algorithms• Written (use LaTeX!) – Submit both zip and pdf!

• Regrade office hours:• Thursday 11am-12pm (Rice 210)• Thursday 4pm-5pm (Rice 501)

5

Page 6: CS 4102: Algorithms

Review: Heap Sort

Idea: Build a heap, repeatedly extract max element from the heap to build a sorted list (form right-to-left)

6

10

9 6

8 7 5 2

4 1 3

Max heap property:Each node is larger

than its children

10 9 6 8 7 5 2 4 1 3

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9 10

Page 7: CS 4102: Algorithms

Review: Heap Sort

7

10

9 6

8 7 5 2

4 1 3

10 9 6 8 7 5 2 4 1 3

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9 10

Remove the max element (i.e. the root) from the heap, and the root with the last element, restore heap property by calling Heapify(root)

Max heap property:Each node is larger

than its children

Page 8: CS 4102: Algorithms

Review: Heap Sort

Remove the max element (i.e. the root) from the heap, and the root with the last element, restore heap property by calling Heapify(root)

8

3

9 6

8 7 5 2

4 1

3 9 6 8 7 5 2 4 1

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9

Max heap property:Each node is larger

than its children

Page 9: CS 4102: Algorithms

Review: Heap Sort

Remove the max element (i.e. the root) from the heap, and the root with the last element, restore heap property by calling Heapify(root)

3

9 6

8 7 5 2

4 1

3 9 6 8 7 5 2 4 1

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9Heapify(node): if node satisfies max heap property, then we are done. Otherwise, swap with the larger child and recurse on that subtree

Max heap property:Each node is larger

than its children

Page 10: CS 4102: Algorithms

Review: Heap Sort

Remove the max element (i.e. the root) from the heap, and the root with the last element, restore heap property by calling Heapify(root)

9

3 6

8 7 5 2

4 1

9 3 6 8 7 5 2 4 1

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9Heapify(node): if node satisfies max heap property, then we are done. Otherwise, swap with the larger child and recurse on that subtree

Max heap property:Each node is larger

than its children

Page 11: CS 4102: Algorithms

Review: Heap Sort

Remove the max element (i.e. the root) from the heap, and the root with the last element, restore heap property by calling Heapify(root)

9

8 6

3 7 5 2

4 1

9 8 6 3 7 5 2 4 1

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9Heapify(node): if node satisfies max heap property, then we are done. Otherwise, swap with the larger child and recurse on that subtree

Max heap property:Each node is larger

than its children

Page 12: CS 4102: Algorithms

Review: Heap Sort

Remove the max element (i.e. the root) from the heap, and the root with the last element, restore heap property by calling Heapify(root)

9

8 6

4 7 5 2

3 1

9 8 6 4 7 5 2 3 1

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9Heapify(node): if node satisfies max heap property, then we are done. Otherwise, swap with the larger child and recurse on that subtree

Max heap property:Each node is larger

than its children

Page 13: CS 4102: Algorithms

Review: Heap Sort

Remove the max element (i.e. the root) from the heap, and the root with the last element, restore heap property by calling Heapify(root)

9

8 6

4 7 5 2

3 1

9 8 6 4 7 5 2 3 1

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9Heapify(node): if node satisfies max heap property, then we are done. Otherwise, swap with the larger child and recurse on that subtree

Max heap property:Each node is larger

than its childrenRunning time: 𝑂 log 𝑛

Page 14: CS 4102: Algorithms

Review: Heap Sort

Idea: Build a heap, repeatedly extract max element from the heap to build sorted list (from right to left)

Run Time?𝑂(𝑛 log 𝑛)

(constants worse than quicksort)

Running time:• Constructing heap by calling Heapify on each node in tree

(bottom up): 𝑂 𝑛 log 𝑛• Extracting maximum element to sort list: 𝑂(𝑛 log 𝑛)

Page 15: CS 4102: Algorithms

Review: Heap Sort

In Place?Yes

Idea: Build a heap, repeatedly extract max element from the heap to build sorted list (from right to left)

When removing an element from the heap, move it to the

(now unoccupied) end of the list

Run Time?𝑂(𝑛 log 𝑛)

(constants worse than quicksort)

Constructing heap is also in-place(just requires calling Heapify)

Page 16: CS 4102: Algorithms

Idea: When removing an element from the heap, move it to the (now unoccupied) end of the list

16

In-Place Heap Sort

10

9 6

8 7 5 2

4 1 3

10 9 6 8 7 5 2 4 1 3

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9 10

Max heap property:Each node is larger

than its children

Page 17: CS 4102: Algorithms

Idea: When removing an element from the heap, move it to the (now unoccupied) end of the list

17

In-Place Heap Sort

3

9 6

8 7 5 2

4 1

3 9 6 8 7 5 2 4 1 10

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9

Max heap property:Each node is larger

than its children

Page 18: CS 4102: Algorithms

Idea: When removing an element from the heap, move it to the (now unoccupied) end of the list

18

In-Place Heap Sort

9

8 6

4 7 5 2

3 1

9 8 6 4 7 5 2 3 1 10

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9

Max heap property:Each node is larger

than its children

Page 19: CS 4102: Algorithms

Idea: When removing an element from the heap, move it to the (now unoccupied) end of the list

19

In-Place Heap Sort

9

8 6

4 7 5 2

3 1

9 8 6 4 7 5 2 3 1 10

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8 9

Max heap property:Each node is larger

than its children

Page 20: CS 4102: Algorithms

Idea: When removing an element from the heap, move it to the (now unoccupied) end of the list

20

In-Place Heap Sort

1

8 6

4 7 5 2

3

1 8 6 4 7 5 2 3 9 10

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8

Max heap property:Each node is larger

than its children

Page 21: CS 4102: Algorithms

Idea: When removing an element from the heap, move it to the (now unoccupied) end of the list

21

In-Place Heap Sort

8

7 6

4 1 5 2

3

8 7 6 4 1 5 2 3 9 10

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

8

Max heap property:Each node is larger

than its children

Page 22: CS 4102: Algorithms

Idea: When removing an element from the heap, move it to the (now unoccupied) end of the list

22

In-Place Heap Sort

7

4 6

3 1 5 2

7 4 6 3 1 5 2 8 9 10

0 1 2 3 4 5 6 7 8 9 10

1

2 3

4 65 7

Max heap property:Each node is larger

than its children

Page 23: CS 4102: Algorithms

Heap Sort

In Place?Yes

Idea: Build a heap, repeatedly extract max element from the heap to build sorted list (from right to left)

Run Time?𝑂(𝑛 log 𝑛)

(constants worse than quicksort)

Adaptive? Stable?No No

Parallelizable?No

Page 24: CS 4102: Algorithms

Sorting Algorithms

Sorting algorithms we have discussed:• Mergesort• Quicksort

Other sorting algorithms (will discuss):• Bubble sort• Insertion sort• Heapsort

24

𝑂(𝑛 log 𝑛)𝑂(𝑛 log 𝑛)

𝑂(𝑛 log 𝑛)

𝑂(𝑛,)𝑂(𝑛,)

Can we do better than 𝑂(𝑛 log 𝑛)?

Page 25: CS 4102: Algorithms

Sorting in Linear Time

Cannot be a comparison sort

Implication: Need to make additional assumption about list contents• Small number of unique values• Small range of values

25

Page 26: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

2 0 2 1 0 31 2 3 4 5 6

𝐶 =

Value 1 appears 2 times

Value 4 appears 1 time

Page 27: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

2 0 2 1 0 31 2 3 4 5 6

𝐶 =

• Compute “running sum” of the number of values less than each value

21 2 3 4 5 6

𝐶 =

Page 28: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

2 0 2 1 0 31 2 3 4 5 6

𝐶 =

• Compute “running sum” of the number of values less than each value

2 21 2 3 4 5 6

𝐶 =

Page 29: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

2 0 2 1 0 31 2 3 4 5 6

𝐶 =

• Compute “running sum” of the number of values less than each value

2 2 41 2 3 4 5 6

𝐶 =

Page 30: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

2 0 2 1 0 31 2 3 4 5 6

𝐶 =

• Compute “running sum” of the number of values less than each value

2 2 4 5 5 81 2 3 4 5 6

𝐶 =

Page 31: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

• Compute “running sum” of the number of values less than each value

2 2 4 5 5 81 2 3 4 5 6

Indices 1-2 has value 1

Index 5 has value 4

Indices 6-8 has value 6

Observation: Value at index 𝑖 is index of the last value of 𝑖 (if there is one)

𝐶 =

Page 32: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

2 2 4 5 5 81 2 3 4 5 6

1 2 3 4 5 6 7 8𝐵 =

𝐶 =

Page 33: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

2 2 4 5 5 81 2 3 4 5 6

1 2 3 4 5 6 7 8𝐵 =

𝐶 =

Page 34: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

2 2 4 5 5 81 2 3 4 5 6

31 2 3 4 5 6 7 8

𝐵 =

Last index of value 3 is 4

𝐶 =

Page 35: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

2 2 3 5 5 81 2 3 4 5 6

31 2 3 4 5 6 7 8

𝐵 =

Last index of value 3 is 4

𝐶 =

Page 36: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

2 2 3 5 5 81 2 3 4 5 6

3 61 2 3 4 5 6 7 8

𝐵 =

𝐶 =

Page 37: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

2 2 3 5 5 71 2 3 4 5 6

3 61 2 3 4 5 6 7 8

𝐵 =

𝐶 =

Page 38: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

2 2 3 5 5 71 2 3 4 5 6

3 6 61 2 3 4 5 6 7 8

𝐵 =

𝐶 =

Page 39: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of C

0 2 2 4 5 51 2 3 4 5 6

1 1 3 3 4 6 6 61 2 3 4 5 6 7 8

𝐵 =

𝐶 =

Page 40: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

• Compute “running sum” of the number of values less than each value

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of CΘ 𝑛 + 𝑘

Θ 𝑘Θ 𝑛

Page 41: CS 4102: Algorithms

Counting Sort

Assumption: Small number of unique values

Idea: Count how many values are less than each element

3 6 6 1 3 4 1 61 2 3 4 5 6 7 8

𝐿 =

• Range is [1, 𝑘] (here, 𝑘 = 6)• Initialize an array 𝐶 of size 𝑘• Count number of times each value occurs

• Compute “running sum” of the number of values less than each value

For each element of 𝐿:Use 𝐶 to find its proper place in 𝐵

Decrement that position of CΘ 𝑛 + 𝑘

Θ 𝑘Θ 𝑛

Runtime: Θ 𝑛 + 𝑘Space: Θ 𝑛 + 𝑘

Page 42: CS 4102: Algorithms

Counting Sort

Why not always use counting sort?For 64-bit numbers, requires an array of length 29: > 10=>• 5 GHz CPU will require > 116 years to initialize the array• 18 Exabytes of data• Total amount of data that Google has

42

Page 43: CS 4102: Algorithms

Somewhere Between 3 and 12 Exabytes

43

Bluffdale, Utah

Page 44: CS 4102: Algorithms

Radix Sort

Idea: Stable sort each digit, from least significant to most significant

44

103 801 401 323 255 823 999 101

0 1 2 3 4 5 6 7

999018255555245

103323823113

512

113 901 555 512 245 800 018 121

8 9 10 11 12 13 14 15

0 1 2 3 4 5 6 7

801401101901121

800

8 9

Assumption: Values are numeric

800 801 401 101 901 121 512 103

0 1 2 3 4 5 6 7

323 823 113 255 555 245 018 999

8 9 10 11 12 13 14 15

Sort each element based on their 1’s place

Page 45: CS 4102: Algorithms

800 801 401 101 901 121 512 103

0 1 2 3 4 5 6 7

323 823 113 255 555 245 018 999

8 9 10 11 12 13 14 15

Radix Sort

Idea: Stable sort each digit, from least significant to most significant

45

Sort each element based on their 10’s place 999255

555245121323823

0 1 2 3 4 5 6 7

512113018

800801401101901103

8 9

Assumption: Values are numeric

Observe: digits in the 1’s place are correctly sorted (because we are using a stable sort)!

Page 46: CS 4102: Algorithms

800 801 401 101 901 121 512 103

0 1 2 3 4 5 6 7

323 823 113 255 555 245 018 999

8 9 10 11 12 13 14 15

Radix Sort

Idea: Stable sort each digit, from least significant to most significant

46

Sort each element based on their 10’s place 999255

555245121323823

0 1 2 3 4 5 6 7

512113018

800801401101901103

8 9

Assumption: Values are numeric

800 801 401 101 901 103 512 113

0 1 2 3 4 5 6 7

018 121 323 823 245 255 555 999

8 9 10 11 12 13 14 15

Page 47: CS 4102: Algorithms

800 801 401 101 901 103 512 113

0 1 2 3 4 5 6 7

018 121 323 823 245 255 555 999

8 9 10 11 12 13 14 15

Radix Sort

Idea: Stable sort each digit, from least significant to most significant

47

Sort each element based on their 100’s place

901999

800801823

512555401323245

255

0 1 2 3 4 5 6 7

101103113121

018

8 9

Assumption: Values are numeric

Observe: digits in the 1’s and 10’s places are correctly sorted (because we are using a stable sort)!

Page 48: CS 4102: Algorithms

800 801 401 101 901 103 512 113

0 1 2 3 4 5 6 7

018 121 323 823 245 255 555 999

8 9 10 11 12 13 14 15

Radix Sort

Idea: Stable sort each digit, from least significant to most significant

48

Sort each element based on their 100’s place

901999

800801823

512555401323245

255

0 1 2 3 4 5 6 7

101103113121

018

8 9

Assumption: Values are numeric

018 101 103 113 121 245 255 323

0 1 2 3 4 5 6 7

401 512 555 800 801 823 901 999

8 9 10 11 12 13 14 15

Page 49: CS 4102: Algorithms

018 101 103 113 121 245 255 323

0 1 2 3 4 5 6 7

401 512 555 800 801 823 901 999

8 9 10 11 12 13 14 15

Radix Sort

Idea: Stable sort each digit, from least significant to most significant

49

Assumption: Values are numeric

Runtime: Θ 𝑑 𝑛 + 𝑏Space: Θ 𝑛 + 𝑏

𝑑: number of digits𝑏: base (“radix”)𝑛: number of values

Page 50: CS 4102: Algorithms

Maximum Sum Subarray Problem

Maximum sum contiguous subarray (MSCS) problem:find the largest contiguous subarray that

maximizes the sum of the values

50

5

0

-4

2

8

1

3

3

7

4

-15

5

2

6

8

7

-20

8

17

9

8

10

-50

11

-5

12

22

13

Page 51: CS 4102: Algorithms

Maximum Sum Subarray Problem

Maximum sum contiguous subarray (MSCS) problem:find the largest contiguous subarray that

maximizes the sum of the values

51

5

0

-4

2

8

1

3

3

7

4

-15

5

2

6

8

7

-20

8

17

9

8

10

-50

11

-5

12

22

13

Page 52: CS 4102: Algorithms

5

0

-4

2

8

1

3

3

7

4

-15

5

2

6

8

7

-20

8

17

9

8

10

-50

11

-5

12

22

13

Divide and Conquer Θ(𝑛 log 𝑛)

52

Divide in half Recursively solve on right

Recursively solve on left

Page 53: CS 4102: Algorithms

5

0

-4

2

8

1

3

3

7

4

-15

5

2

6

8

7

-20

8

17

9

8

10

-50

11

-5

12

22

13

Divide and Conquer Θ(𝑛 log 𝑛)

53

Divide in halfRecursively solve on left

Recursively solve on right

19 25

Page 54: CS 4102: Algorithms

5

0

-4

2

8

1

3

3

7

4

-15

5

2

6

8

7

-20

8

17

9

8

10

-50

11

-5

12

22

13

Divide and Conquer Θ(𝑛 log 𝑛)

54

Divide in halfRecursively solve on left

Recursively solve on right

Combine: Find largest sum that spans the cut

Largest sum that ends here

+ Largest sum that starts here

2-13-6-3-716 -20-42-37135-128

19 25

Page 55: CS 4102: Algorithms

5

0

-4

2

8

1

3

3

7

4

-15

5

2

6

8

7

-20

8

17

9

8

10

-50

11

-5

12

22

13

Divide and Conquer Θ(𝑛 log 𝑛)

55

Divide in halfRecursively solve on left

Recursively solve on right

Combine: Find largest sum that spans the cut

Largest sum that ends here

+ Largest sum that starts here

2-13-6-3-716 -20-42-37135-128

19 25

19𝑇 𝑛 = 2𝑇 ⁄𝑛 2 + Θ 𝑛 ∈ Θ 𝑛 log 𝑛

Page 56: CS 4102: Algorithms

Divide and Conquer Summary

Divide• Break the list in half

Conquer• Find the best subarrays on the left and right

Combine• Find the best subarray that “spans the divide”• Output best subarray among the three possible subarrays

Typically multiple subproblemsTypically all roughly the same size

Page 57: CS 4102: Algorithms

Generic Divide and Conquer Templatedef myDCalgo(problem):

if baseCase(problem):solution = solve(problem) # brute force if necessaryreturn solution

subproblems = divide(problem)for sub in subproblems:

subsolutions.append(myDCalgo(sub))solution = combine(subsolutions)return solution

57

Page 58: CS 4102: Algorithms

MSCS Divide and Conquer Θ(𝑛 log 𝑛)def MSCS(list):

if list.length < 2:return list[0] # list of size 1 the sum is maximal

{listL, listR} = divide(list)for list in {listL, listR}:

subsolutions.append(MSCS(list))solution = max(solnL, solnR, span(listL, listR))return solution

58

Page 59: CS 4102: Algorithms

Types of “Divide and Conquer”

Divide and Conquer• Break the problem up into multiple subproblems of similar size and

recursively solve• Examples: Karatsuba, closest pair of points, Mergesort, Quicksort

Decrease and Conquer• Break the problem into a single smaller subproblem and recursively solve• Examples: Mission Impossible, Quickselect, binary search

Page 60: CS 4102: Algorithms

Pattern So Far

Typically looking to divide the problem by some fraction (½, ¼ the size)

Not necessarily always the best!• Sometimes, we can write faster algorithms by finding unbalanced splits