Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 10 - Monday CS 113.

Similar presentations


Presentation on theme: "Week 10 - Monday CS 113."— Presentation transcript:

1 Week 10 - Monday CS 113

2 Last time What did we talk about last time?
Reading (and writing, sort of) files in Python Lab 9

3 Questions?

4 Project 3

5 Hard Problems

6 Hamiltonian Cycle The Eulerian Cycle problem asked if you could start at some node, cross every edge once, and return to the start The Hamiltonian Cycle problem asks if you can start at some node, visit every node only once, and return to the start In other words, find a tour Sounds easy, right?

7 Find the Hamiltonian Cycle
On this graph: A D B E C D A E B C

8 Find the Hamiltonian Cycle
Now, on this graph: There isn’t one!

9 Find the Hamiltonian Cycle
Now, on this graph: Hmmm…

10 Traveling Salesman Problem: Hamiltonian Cycle Meets Shortest Path
Given a graph, find the shortest tour that visits every node and comes back to the starting point Like a lazy traveling salesman who wants to visit all possible clients and then return to his home

11 What’s the shortest tour?
Find the shortest TSP tour: Starts anywhere Visits all nodes Has the shortest length of such a tour A 5 6 4 3 2 3 E B D 3 F 7 C

12 How can we always find the shortest tour?
Strategies: Always add the nearest neighbor Randomized approaches Try every possible combination Why are we only listing strategies?

13 Best Solution to TSP So far we haven’t given a foolproof solution to TSP Let’s look at two possibilities: Greedy Solution: Pick the closest neighbor Brute Force: Try all possibilities

14 Greedy Doesn’t Work We are tempted to always take the closest neighbor, but there are pitfalls Greedy Optimal

15 Brute Force is Brutal In a completely connected graph, we can try any sequence of nodes If there are n nodes, there are (n – 1)! tours For 30 cities, 29! = If we can check 1,000,000,000 tours in one second, it will only take about 20,000 times the age of the universe to check them all We will (eventually) get the best answer!

16 Running time How do we measure the amount of time an algorithm takes?
Surely running TSP on 4 cities takes less time than running TSP on 1,000 cities 1,000 cities in a straight line seems easier than 1,000 cities randomly scattered We use Big Oh notation!

17 What’s the best time for TSP?
No one knows how to find the best solution to TSP in an efficient amount of time The best solutions known take O(2n) For a general graph, no good approximation even exists For a graph with the triangle inequality, there is an approximation that yields a tour no more than 3/2 the optimal Some variations on the problem are easier than others

18 Hard problems Is TSP the hardest problem there is?
Are there other problems equally hard? How do we compare the difficulty of one problem to another?

19 NP-completeness TSP is one of many problems which are called NP-complete All of these problems share the characteristic that the only way we know to find best solution uses brute force All NP-complete problems are reducible to all other NP-complete problems An efficient solution to one would guarantee an efficient solution to all

20 NP-complete problems on graphs
Traveling Salesman Problem Hamiltonian Cycle (and Path) Let’s see just a couple more…

21 Graph Coloring Find the smallest number of colors for coloring nodes such that no two adjacent nodes have the same color E A D B F C A E B D F C

22 Graph Coloring What about this graph?

23 Graph Coloring Like TSP and Hamiltonian Cycle, large graphs get really hard to find the smallest coloring for It might not be obvious, but graph coloring has practical applications Perhaps the most common example is register allocation inside of a compiler

24 Maximum Clique Find the largest complete subgraph in a given graph
This graph has a clique of size 3

25 Maximum Clique What about this graph?
This graph has a clique of size 4 As before, a large graph can be very difficult

26 Knapsack problem Not all NP-complete problems are graph problems
The knapsack problem is the following: Imagine that you are Indiana Jones You are the first to open the tomb of some long-lost pharaoh You have a knapsack that can hold m pounds of loot, but there's way more than that in the tomb Because you're Indiana Jones, you can instantly tell how much everything weighs and how valuable it is You want to find the most valuable loot that weighs less than or equal to m pounds

27 Subset sum This one is a little bit mathematical
Say you have a set of numbers Somebody gives you a number k Is there any subset of the numbers in your set that add up to exactly k? Example: Set: { 3, 9, 15, 22, 35, 52, 78, 141} Is there a subset that adds up to exactly 100? What about 101?

28 NP NP is actually a class of problem
Problems in NP can be solved in polynomial time on a non-deterministic computer A deterministic computer is the kind you know: First it has to consider possibility A, then, it can consider possibility B

29 Deterministic vs. non-deterministic
A non-deterministic computer (which, as far as we know, only exists in our imagination) can consider both possibility A and possibility B at the same time Deterministic A B C D E F A B C D E F Non-Deterministic

30 P P is the class of decision problems that can be solved in polynomial time by a deterministic computer Lots of great problems are in P: Is this list sorted? Is this number prime? Is the shortest path from node A to node B of length 37? It's unknown whether some problems are in P: Does this number have exactly two factors? Is this graph equivalent to this other graph?

31 NP-complete Everything in P is also in NP
Some problems are the “hardest” problems in NP This means that any problem in NP can be converted into one of these problem in polynomial time These problems make up the class NP-complete NP-complete NP-complete

32 Decisions, decisions Notice that P, NP, and NP-complete are all decision problems So, the TSP we stated is not technically NP-complete The NP-complete version is: Is there a tour of length less than or equal to 24 in this graph? The optimization versions of NP-complete problems are called NP-hard

33 Easy to check vs. easy to answer
Computer scientists view problems in P as "easy to answer" They can be computed in polynomial time Problems in NP are "easy to check" An answer can be checked in polynomial time For example, if someone gives you a Traveling Salesman tour, you can verify that it is a legal tour of the required length But is easy to check the same as easy to answer?

34 Fabulous cash prizes These NP-complete problems are very hard
Many of them are really useful Clay Mathematics Institute has offered a $1,000,000 prize You can do one of two things to collect it: Find an efficient solution to any of the problems Prove that one cannot have an efficient solution

35 What if P = NP? Most computer scientists think that P ≠ NP
But if it were Most things could be perfectly scheduled e.g., the best room for a given number of students and the time preferences of everyone involved All routing and path planning (UPS, military, etc.) would be optimal It might be possible to devise perfect genetic therapies for certain conditions It would be possible to prove all kinds of previously unproven theorems in mathematics

36 What if P = NP? (The Bad) On the other hand, if P = NP, it might also mean: Most of our encryption algorithms would be broken All computer, Internet, and banking security would be worthless Could creativity be doomed? If recognizing something good was the same as creating something good… who knows?

37 A final word from an MIT professor
If P=NP, then the world would be a profoundly different place than we usually assume it to be. There would be no special value in “creative leaps,” no fundamental gap between solving a problem and recognizing the solution once it’s found. Everyone who could appreciate a symphony would be Mozart; everyone who could follow a step-by-step argument would be Gauss; everyone who could recognize a good investment strategy would be Warren Buffett. It’s possible to put the point in Darwinian terms: if this is the sort of universe we inhabited, why wouldn’t we already have evolved to take advantage of it? Scott Aaronson

38 Upcoming

39 Next time… Finish NP-completeness Turing machines Halting problem

40 Reminders Design document for final project is due Friday
Start working on Project 4 Exam 2 is next Monday We'll review on Friday Talk: Creativity in the Many Areas of Game Development at Firaxis Games Barry Caudill Wednesday 11am-12:25 in E273


Download ppt "Week 10 - Monday CS 113."

Similar presentations


Ads by Google