1 of 34

CSE 373 Autumn 2024�Fun With Reductions!

2 of 34

Reductions

2

Shows how two different problems relate to each other

MOVIE TIME!

3 of 34

MacGyver’s Reduction

3

Reduction

Input: Closed Door

Problem we don’t know how to solve

Lighting a fire

Problem we do know how to solve

Aim duct at door, insert keg

Alcohol & matches

Method for lighting a fire

Put fire under the Keg

Opening a door

Input: Wood

Output: Fire!

Output: Open Door

Combining all three arrows gives an algorithm for opening a door

4 of 34

Seam Finding Reduces to Shortest Path

4

Problem we don’t know how to solve

Finding a Seam

Problem we do know how to solve

Single-Source Shortest Path

Dijkstra’s Algorithm

Pixels to nodes, edges to neighbors, weight is energy, add source and sink

Reduction

Input: Graph

Input: Image

Output: Single-source Shortest Path Tree

Find shortest path from source to sink

Output: A Seam

5 of 34

Patch Finding Reduces to Cycle Detection

5

Problem we don’t know how to solve

Finding a Patch

Problem we do know how to solve

Cycle Detection

DFS

Solution to Exam 3

Reduction

Input: Graph

Input: Image

Output: All Cycles

Solution to Exam 3

Output: All Patches

1

6 of 34

Detect Melanoma (Group Analysis 3)

6

Problem we don’t know how to solve

Detect Melanoma

Problem we do know how to solve

Finding a Patch

Identify high-energy

and low-energy pixels

Reduction

Photo of a patient’s skin

1

Input: Image

Output: All Patches

1

Patches are melanoma?

7 of 34

Detect Melanoma (Group Analysis 3)

7

Detect Melanoma

Find Patches

Reduction

DFS

Reduction

Cycle Detection

All Cycles

1

Photo of a patient’s skin

1

8 of 34

Reductions Enable New Algorithms!

  • Create an algorithm for a new problem by using one you already know!
  • More algorithms = More opportunities!
  • The problem you reduced to could itself be solved using a reduction!

9 of 34

Sorting “Reduces To” Priority Queue ADT

9

Problem we don’t know how to solve

Sorting a List

Problem we do know how to solve

Priority Queue ADT

Add/RemoveMax Algorithms

Add all items

Reduction

Input: A List

removeMax until empty, move value to the end of the list

Output: A Sorted List

8

17

22

30

2

12

19

24

Binary Max Heap

2

8

12

17

19

22

24

30

We named this entire path “Heap Sort”

 

10 of 34

Exam 2 Impossible Data Structure

  •  

11 of 34

Another use of Reductions

11

 

Reduction

An algorithm for A

Suppose I knew a worst-case lower bound for Problem A

This path’s running time must be at least that lower bound

 

 

 

Fast running time

Fast running time

Slow Running time

Unknown Running time

12 of 34

Two Ways to use Reductions

Suppose we have a “fast” reduction from A to B

  1. A “fast” algorithm for B gives a fast algorithm for A

  • If we have a worst-case lower bound for A, we also have one for B

 

 

 

 

 

 

fast

fast

If B is fast

Then A is fast

If A is slow

Then B is slow

fast

13 of 34

Pairing Problem

  •  

8

17

22

30

2

12

19

24

3

13

12

9

2

21

30

33

8

17

22

30

2

12

19

24

3

13

12

9

2

21

30

33

14 of 34

Sorting Reduces to Pairing

14

Problem with a known lower bound

Sorting a List

Problem without a known lower bound

Pairing

Create the list:

Reduction

Input: Two Lists

Output: A Pairing

Add the item paired with 0, then 1, then 2, …

Input: A List

Output: A Sorted List

8

17

22

30

2

12

19

24

2

8

12

17

19

22

24

30

0

1

2

3

4

5

6

7

8

17

22

30

2

12

19

24

0

1

2

3

4

5

6

7

8

17

22

30

2

12

19

24

0

1

2

3

4

5

6

7

 

15 of 34

Sorting Reduces to Pairing

15

Problem with a known lower bound

Sorting a List

Problem without a known lower bound

Pairing

Create the list:

Reduction

Input: Two Lists

Output: A Pairing

Add the item paired with 0, then 1, then 2, …

Input: A List

Output: A Sorted List

8

17

22

30

2

12

19

24

2

8

12

17

19

22

24

30

0

1

2

3

4

5

6

7

8

17

22

30

2

12

19

24

0

1

2

3

4

5

6

7

8

17

22

30

2

12

19

24

0

1

2

3

4

5

6

7

 

 

16 of 34

A “Hard” Problem: Finding Duplicates

  •  

103

801

401

323

255

323

999

101

113

901

555

512

245

800

018

121

False

True

17 of 34

Finding Duplicates Reduces to Sorting

17

Sorting

Reduction

Input: A List

Check if the any adjacent items are equal

Input: A List

Output: A Sorted List

8

17

22

30

2

12

19

24

2

8

12

17

19

22

24

30

8

17

22

30

2

12

19

24

Merge Sort

Find Duplicates

Output: True/False

 

 

 

This gives us no information about a lower bound for Find Duplicates!

18 of 34

A “Hard” Problem: Finding Duplicates

  •  

103

801

401

323

255

323

999

101

113

901

555

512

245

800

018

121

False

True

19 of 34

Closest Pair of Points

19

1

2

3

4

5

6

7

8

Given:

A list of points

Return:

Pair of points with smallest distance apart

20 of 34

Reducing Find Duplicates to CPP

  •  

5

7

9

8

5,5

7,7

8,8

9,9

6

3

6

9

3,3

6,6

9,9

6,6

Running time?

How to we find the answer to Element Uniqueness from Closest Pair?

 

Check if closest pair’s distance is 0

Running time?

 

21 of 34

Reductions for Lower-Bound on CPP

21

 

 

True/False

Reduction

 

 

Closest Pair

of Points

 

 

5

7

9

8

6

3

6

9

Find Duplicates

Is closest distance > 0?

 

22 of 34

Two Ways to use Reductions

Suppose we have a “fast” reduction from A to B

  1. A “fast” algorithm for B gives a fast algorithm for A

  • If we have a worst-case lower bound for A, we also have one for B

 

 

 

 

 

 

fast

fast

If B is fast

Then A is fast

If A is slow

Then B is slow

fast

23 of 34

Party Problem

23

Draw Edges between people who don’t get along

How many people can I invite to a party if everyone must get along?

24 of 34

Independent Set

  •  

24

25 of 34

Example

25

Independent set of size 6

26 of 34

Generalized Baseball

26

27 of 34

Generalized Baseball

27

Need to place defenders on bases such that every edge is defended

How many defenders would suffice?

28 of 34

Vertex Cover

  •  

28

29 of 34

Example

29

Vertex cover of size 5

30 of 34

Relating Independent Set to Vertex Cover

  •  

30

Independent Set

Vertex Cover

31 of 34

Relating Vertex Cover to Independent Set

  •  

31

Independent Set

Vertex Cover

32 of 34

Independent Set Reduces to Vertex Cover

32

Independent Set

Vertex Cover

Solution for Vertex Cover

Solution for Independent Set

 

Reduction

Any Algorithm for Vertex Cover

Take the opposite

set of nodes

 

Input: A graph and a number

 

 

33 of 34

Independent Set Reduces to Vertex Cover

33

Vertex Cover

Independent Set

Solution for Independent Set

Solution for Vertex Cover

 

Reduction

Any Algorithm for Independent Set

Take the opposite

set of nodes

 

Input: A graph and a number

 

 

34 of 34

Solving Vertex Cover and Independent Set

  •  

Either both problems have a fast algorithm or neither does!