Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complexity ©D.Moshkovitz 1 Paths On the Reasonability of Finding Paths in Graphs.

Similar presentations


Presentation on theme: "Complexity ©D.Moshkovitz 1 Paths On the Reasonability of Finding Paths in Graphs."— Presentation transcript:

1 Complexity ©D.Moshkovitz 1 Paths On the Reasonability of Finding Paths in Graphs

2 Complexity ©D.Moshkovitz 2 Introduction Objectives: –To introduce more graph theory problems. Overview: –Hamiltonian paths –Eulerian paths

3 Complexity ©D.Moshkovitz 3 Hamiltonian Path Instance: a directed graph G=(V,E) and two vertices s,t  V. Problem: To decide if there exists a path from s to t, which goes through each node once.

4 Complexity ©D.Moshkovitz 4 Can You Find One Here? st

5 Complexity ©D.Moshkovitz 5 HAMPATH is in NP Non-deterministically choose v 1,…,v n  V (n=|V|). For any 1  i,j  n, verify v i  v j. Verify s=v 1 and t=v n. For any 1  i  n, verify (v i,v i+1 )  E.

6 Complexity ©D.Moshkovitz 6 HAMPATH is NP-Complete Proof: We’ll show 3SAT  p HAMPATH. SIP 262-267 s t... pp

7 Complexity ©D.Moshkovitz 7 Representing Variables For any variable x i, Diamond...

8 Complexity ©D.Moshkovitz 8 Representing Clauses For any clause c i,

9 Complexity ©D.Moshkovitz 9 High-Level Structure... x1x2...xlx1x2...xl c1c2c3...ckc1c2c3...ck s t

10 Complexity ©D.Moshkovitz 10 The Internal Structure of the Diamonds k pairs of internal nodes Diamond...

11 Complexity ©D.Moshkovitz 11 Connecting Clauses to Variables If the clause c j contains the literal x i, j’th pair xixi cjcj...

12 Complexity ©D.Moshkovitz 12 Connecting Clauses to Variables If the clause c j contains the literal  x i, j’th pair xixi cjcj...

13 Complexity ©D.Moshkovitz 13 Construction Completed This concludes the construction. Its size is polynomial in the size of the formula (Check!). We proceed to prove correctness.

14 Complexity ©D.Moshkovitz 14 Completeness Assume there exists a satisfying assignment for the 3CNF formula. Let us demonstrate a Hamiltonian tour on the graph.

15 Complexity ©D.Moshkovitz 15 Assignment  Path If the variable x i is assigned TRUE,...

16 Complexity ©D.Moshkovitz 16 Assignment  Path If the variable x i is assigned FALSE,...

17 Complexity ©D.Moshkovitz 17 Covering the Clauses If the clause c j is satisfied due to the literal x i, xixi cjcj... j’th pair

18 Complexity ©D.Moshkovitz 18... Covering the Clauses If the clause c j is satisfied due to the literal  x i, xixi cjcj j’th pair

19 Complexity ©D.Moshkovitz 19 Soundness Assume there exists a Hamiltonian tour on the graph, Let us construct a satisfying assignment for the 3CNF formula.

20 Complexity ©D.Moshkovitz 20 Observation Every Hamiltonian path must contain either the entire right path or the entire left path of each diamond....

21 Complexity ©D.Moshkovitz 21 Path  Assignment For each variable, decide on its truth value, According to the direction of the path in its diamond....

22 Complexity ©D.Moshkovitz 22 x1x2...xlx1x2...xl... s t Observation cjcj A Hamiltonian path cannot jump from inside one diamond to another Proof Idea: Assume it can and observe this node

23 Complexity ©D.Moshkovitz 23 Satisfaction Note that because of the observationthe observation And the fact the path goes through all clause nodes, All clauses are satisfied

24 Complexity ©D.Moshkovitz 24 The Punch Line HAMPATH is NP-Complete.

25 Complexity ©D.Moshkovitz 25 Food for Thought… Is HAMCYCLE (Whether there exists a simple cycle which goes through all nodes) NP-Complete?

26 Complexity ©D.Moshkovitz 26 Food for Thought… What about finding Hamiltonian paths in undirected graphs?

27 Complexity ©D.Moshkovitz 27 Similar Problem Children usually like this riddle: Can you draw the following shape in one line?

28 Complexity ©D.Moshkovitz 28 Eulerian Path Instance: an undirected graph G=(V,E) and two vertices s  t  V. Problem: To decide if there exists a path from s to t, which goes through each edge exactly once.

29 Complexity ©D.Moshkovitz 29 Can You Find One Here? st

30 Complexity ©D.Moshkovitz 30 Eulerian Paths Vs. Hamiltonian Paths What do you make of this problem? Is it reducible to HAMPATH? Or vice-versa? ?

31 Complexity ©D.Moshkovitz 31

32 Complexity ©D.Moshkovitz 32 The Euler Theorem Theorem: A connected graph has an Eulerian path from s to t iff 1.s and t’s degrees are odd. 2.the degree of all other vertices is even.

33 Complexity ©D.Moshkovitz 33 First Direction Assume there is an Eulerian path from s to t in the graph. Let us prove all degrees, but s and t’s, are odd.

34 Complexity ©D.Moshkovitz 34 Analyzing Degrees Observe the path. It passes through all edges. For internal vertices, it gets out every time it gets in, thus adding 2 to the degree each time. Except it first gets out of s and finally gets in to t.

35 Complexity ©D.Moshkovitz 35 Second Direction Assume all degrees, but s and t’s, are even. Let us describe an algorithm which finds an Eulerian path from s to t.

36 Complexity ©D.Moshkovitz 36 Walks Start at s, While there are new edges –Arbitrarily choose such, –And walk on it.

37 Complexity ©D.Moshkovitz 37 Observation Claim: Such a walk must get stuck at t. Proof: After leaving s, t is the only vertex whose degree is odd. Thus we can get out of every other vertex we visit.

38 Complexity ©D.Moshkovitz 38 Were All Edges Visited? Not necessarily! Check out this example: st

39 Complexity ©D.Moshkovitz 39 Observation Claim: If there are edges not visited, than there exists such edge which “hits” a visited vertex. Proof: By graph connectivity. st

40 Complexity ©D.Moshkovitz 40 Observation Claim: A walk that starts at the visited vertex must get stuck at that vertex itself. Proof: After leaving the visited vertex it remains the only vertex the number of new edges hitting it is odd.

41 Complexity ©D.Moshkovitz 41 Putting the Pieces Together We can add the new walk to the old one and so cover at least one more edge. Now repeat this process if there are more uncovered edges. … s t ……

42 Complexity ©D.Moshkovitz 42 The Punch Line There is a polynomial time algorithm for the Eulerian path problem.

43 Complexity ©D.Moshkovitz 43 Food for Thought… How would you efficiently implement the Euler algorithm?

44 Complexity ©D.Moshkovitz 44 Summary NP P NPC EULERPATH HAMPATH

45 Complexity ©D.Moshkovitz 45 Summary In this lecture we’ve examined few problems related to paths in graphs. We’ve shown that finding a path which visits all vertices (Hamiltonian) is NP-Hard. While we can efficiently find paths which visit all edges (Eulerian). 


Download ppt "Complexity ©D.Moshkovitz 1 Paths On the Reasonability of Finding Paths in Graphs."

Similar presentations


Ads by Google