Download presentation
Presentation is loading. Please wait.
Published bySamson Adrian Leonard Modified over 9 years ago
1
Week 13 - Monday
2
What did we talk about last time? B-trees Hamiltonian tour Traveling Salesman Problem
7
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
8
Find the shortest TSP tour: Starts anywhere Visits all nodes Has the shortest length of such a tour E E A A D D B B F F C C 5 6 4 4 3 5 2 7 3 3
9
Strategies: Always add the nearest neighbor Randomized approaches Try every possible combination Why are we only listing strategies?
10
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
11
We are tempted to always take the closest neighbor, but there are pitfalls GreedyOptimal
12
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! = 8841761993739701954543616000000 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!
13
No one knows how to find the best solution to TSP in an efficient amount of time 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
14
Is TSP the hardest problem there is? Are there other problems equally hard? How do we compare the difficulty of one problem to another?
15
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
16
Traveling Salesman Problem Hamiltonian Cycle (and Path) Let’s see just a couple more…
17
Find the smallest number of colors for coloring nodes such that no two adjacent nodes have the same color E E A A D D B B F F C C E A D B F C
18
What about this graph?
19
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
20
Find the largest complete subgraph in a given graph This graph has a clique of size 3 E E A A D D B B F F C C
21
What about this graph? This graph has a clique of size 4 As before, a large graph can be very difficult E E A A D D B B F F C C
22
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
23
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?
24
These NP-complete problems are very hard Many of them are really useful Especially if you are a lazy traveling salesman 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
26
A Turing machine is a mathematical model for computation It consists of a head, an infinitely long tape, a set of possible states, and an alphabet of characters that can be written on the tape A list of rules saying what it should write and should it move left or right given the current symbol and state 1011110000 A A
27
3 state, 2 symbol “busy beaver” Turing machine: Starting state A Tape Symbol State AState BState C WriteMoveNextWriteMoveNextWriteMoveNext 01RB0RC1LC 11RHALT1RB1LA
28
If an algorithm exists, a Turing machine can perform that algorithm In essence, a Turing machine is the most powerful model we have of computation Power, in this sense, means the ability to compute some function, not the speed associated with its computation
29
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
30
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 CDEF A B C D E F Non- Deterministic
31
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 largest number in this B-tree equal to 38? Many problems are unknown: Does this number have exactly two factors? Is this graph equivalent to this other graph?
32
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
33
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
34
EXPSPACE Exponential space EXP Exponential time on a deterministic Turing machine PSPACE Polynomial space NP Polynomial time on a non- deterministic Turing machine PP Polynomial time on a deterministic Turing machine LL Logarithmic space on a deterministic Turing machine EXPSPACE EXP PSPACE NP P L
35
RE Co-RE There are also problems that cannot be solved by any computer (or algorithm) in a finite amount of time Problems in R can be solved by an algorithm in a finite amount of time Problems in RE can reach a "yes" answer in a finite amount of time, but no algorithm is guaranteed to reach completion if the answer is "no" Problems in Co-RE can reach a "no" answer in a finite amount of time, but no algorithm is guaranteed to reach completion if the answer is "yes" R EXPSPACE R is the set of recursive decision problems RE is the set of recursively enumerable decision problems Co-RE is the complement of set RE
36
Given a Turing machine and input x, does it reach the halt state? It turns out that this problem is undecidable That means that there is no algorithm that can be to determine if any Turing machine will go into an infinite loop Consequently, there is no algorithm that can take any program and check to see if it goes into an infinite loop
37
Given two finite lists of words A and B, can you pick k words (repetitions allowed) from A and k words (repetitions allowed) from B so that the words from A concatenated are exactly the same string as the words from B concatenated Example: Solution: aa + bb + bb = aabbbb = a + a + bbbb The Post correspondence problem (PCP) is undecidable (there is no algorithm that can solve all instances of it) AB aabbbb abaa bbabba
39
Elementary sorts Merge sort Quicksort Priority queues Heapsort
40
Work on Project 4 Work on Assignment 6 Read sections 2.1 through 2.4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.