Download presentation

Presentation is loading. Please wait.

Published byKyleigh Pearcy Modified over 2 years ago

2
§6 Applications of Depth-First Search /* a generalization of preorder traversal */ void DFS ( Vertex V ) /* this is only a template */ { visited[ V ] = true; /* mark this vertex to avoid cycles */ for ( each W adjacent to V ) if ( !visited[ W ] ) DFS( W ); } /* T = O( |E| + |V| ) as long as adjacency lists are used */ 0 123 45 6 DFS ( 0 ) 1. Undirected Graphs void ListComponents ( Graph G ) { for ( each V in G ) if ( !visited[ V ] ) { DFS( V ); printf(“\n“); } 7 8 0 1 4 6 5 2 3 7 8 1/15

3
§6 Applications of Depth-First Search 2. Biconnectivity Articulation point Biconnected graph v is an articulation point if G’ = DeleteVertex( G, v ) has at least 2 connected components. G is a biconnected graph if G is connected and has no articulation points. A biconnected component is a maximal biconnected subgraph. 〖 Example 〗 0 1 23 4 8 7 5 6 9 Connected graph 0 1 1 23 4 35 8 7 7 5 6 7 9 Biconnected components Note: No edges can be shared by two or more biconnected components. Hence E(G) is partitioned by the biconnected components of G. 2/15

4
§6 Applications of Depth-First Search Finding the biconnected components of a connected undirected G 0 1 23 4 8 7 5 6 9 Use depth first search to obtain a spanning tree of G DFS ( 3 ) 0 1 2 3 4 5 6 7 89 Depth first spanning tree 3 45 2 1 0 6 7 98 0 1 2 3 4 5 6 7 89 Depth first number (Num) Find the articulation points in G The root is an articulation point iff it has at least 2 children Any other vertex u is an articulation point iff u has at least 1 child, and it is impossible to move down at least 1 step and then jump up to u’s ancestor. Back edges ::= (u, v) tree and u (or v) is an ancestor of v (or u). Note: If u is an ancestor of v, then Num( u ) < Num( v ). 3/15

5
§6 Applications of Depth-First Search 3 45 2 1 0 6 7 98 0 1 2 3 4 5 6 7 89 vertex Num Low 0123456789 4320156798 0054005598 Therefore, u is an articulation point iff (1) u is the root and has at least 2 children; or (2) u is not the root, and has at least 1 child such that Low( child ) Num( u ). Please read the pseudocodes on p.327 and p.329 for more details. 4/15

6
§6 Applications of Depth-First Search 3. Euler Circuits Draw each line exactly once without lifting your pen from the paper – Euler tour Draw each line exactly once without lifting your pen from the paper, AND finish at the starting point – Euler curcuit 〖 Proposition 〗 An Euler circuit is possible only if the graph is connected and each vertex has an even degree. 〖 Proposition 〗 An Euler tour is possible if there are exactly two vertices having odd degree. One must start at one of the odd-degree vertices. 5/15

7
§6 Applications of Depth-First Search 2 6 9 8 3 7 1 12 4 10 5 11 Note: The path should be maintained as a linked list. For each adjacency list, maintain a pointer to the last edge scanned. T = O( |E| + |V| ) Note: The path should be maintained as a linked list. For each adjacency list, maintain a pointer to the last edge scanned. T = O( |E| + |V| ) Find a simple cycle in an undirected graph that visits every vertex – Hamilton cycle Home work: Self-study the digraphs and strong components on p. 331-334 and do p.342 9.27 DFS 6/15

8
§7 NP-Completeness Recall: Euler circuit problem: Find a path that touches every edge exactly once. Hamilton cycle problem: Find a single cycle that contains every vertex. Single-source unweighted shortest-path problem Single-source unweighted longest-path problem No known algorithms that are guaranteed to run in polynomial time. 7/15

9
§7 NP-Completeness Easy vs. Hard The easiest: O( N ) – since we have to read inputs at least once. The hardest:– undecidable problems. The great mathematician David Hilbert at the 1900 International Congress of Mathematicians outlined 23 research problems to be investigated in the coming century. One of the problems is the question of Decidability — Could there exist, at least in principle, any definite method or process by which all mathematical questions could be decided? Kurt Gödel proved in 1931 that not all true statements that evolve from an axiomatic system can be proven – we can never know everything nor prove everything we discover. This statement is a lie. 8/15

10
§7 NP-Completeness 【 Example 】 Halting problem: Is it possible to have your C compiler detect all infinite loops? Answer:No. Proof: If there exists an infinite loop-checking program, then surely it could be used to check itself. Loop( P ) { /* 1 */ if ( P(P) loops )print (YES); /* 2 */ else infinite_loop(); } What will happen to Loop( Loop ) ? Terminates /* 2 */ is trueLoops Loops /* 1 */ is trueTerminates 9/15

11
§7 NP-Completeness The Class NP TURING MACHINE Alan Mathison Turing was born on 23 June 1912 in a nursing home in Paddington, London. In four inadequate words Alan Turing appears now as the Founder of Computer Science. During the Second World War, Turing made an important contribution on penetrating the mechanical Enigma cipher used by Germany. In 1944, at the invasion of Normandy that Allied control of the Atlantic allowed, Alan Turing was almost uniquely in possession of three key ideas: (1) his own 1936 concept of the universal machine (2) the potential speed and reliability of electronic technology (3) the inefficiency in designing different machines for different logical processes 10/15

12
§7 NP-Completeness Combined, these ideas provided the principle, the practical means, and the motivation for the modern computer, a single machine capable of handling any programmed task. He himself was as eager as anyone in the world to bring them together, and was spurred even more by a fourth idea: that the universal machine should be able to acquire and exhibit the faculties of the human mind. Even in 1944 he spoke to Donald Bayley of 'building a brain'. He was found by his cleaner when she came in on 8 June 1954. He had died the day before of cyanide poisoning, a half-eaten apple beside his bed. His mother believed he had accidentally ingested cyanide from his fingers after an amateur chemistry experiment, but it is more credible that he had successfully contrived his death to allow her alone to believe this. The coroner's verdict was suicide. More details can be found at http:\\www.turing.org.uk. 11/15

13
§7 NP-CompletenessTask To simulate any kind of computation which a mathematician can do by some arithmetical method (assuming that the mathematician has infinite time, energy, paper and pen, and is completely dedicated to the work). Components Infinite Memory Scanner and Operations Change the finite control state. Erase the symbol in the unit currently pointed by head, and write a new symbol in. Head moves one unit to the left (L), or to the right (R), or stays at its current position (S). Scanner............ Infinite 1-dimensional tape(s) divided into units. DATA storage Finite state controller: control head movements according to current state and the symbol that head is pointing to. INSTRUCTION storage One head can point to one and only one unit at each state, and it may move at most one unit to the left or right. 12/15

14
§7 NP-Completeness A Deterministic Turing Machine executes one instruction at each point in time. Then depending on the instruction, it goes to the next unique instruction. A Nondeterministic Turing Machine is free to choose its next step from a finite set. And if one of these steps leads to a solution, it will always choose the correct one. Undecidable problems are still undecidable. NP : Nondeterministic polynomial-time The problem is NP if we can prove any solution is true in polynomial time. 【 Example 】 Hamilton cycle problem: Find a single cycle that contains every vertex – does this simple circuit include all the vertices? NP Note: Not all decidable problems are in NP. For example, consider the problem of determining whether a graph does not have a Hamiltonian cycle. 13/15

15
§7 NP-Completeness NP-Complete Problems -- the hardest An NP-complete problem has the property that any problem in NP can be polynomially reduced to it. If we can solve any NP-complete problem in polynomial time, then we will be able to solve, in polynomial time, all the problems in NP! 【 Example 】 Suppose that we already know that the Hamilton cycle problem is NP-complete. Prove that the traveling salesman problem is NP-complete as well. Traveling salesman problem: Given a complete graph G=(V, E), with edge costs, and an integer K, is there a simple cycle that visits all vertices and has total cost K? 14/15

16
Proof: TSP is obviously in NP since it is easy to check a solution. §7 NP-Completeness V1V1 V2V2 V3V3 V4V4 V5V5 1 1 1 1 1 1 2 2 2 2 K = |V| G has a Hamilton cycle iff G’ has a traveling salesman tour of total weight |V|. The first problem that was proven to be NP-complete was the satisfiability problem: Input a boolean expression and ask if it has an assignment to the variables that gives the expression a value of 1. Cook showed in 1971 that all the problems in NP could be transformed to satisfiability. He proved it by solving this problem on a Turing nondeterministic machine in polynomial time. Home work: p.344 9.39 Show that the clique problem is polynomially reducible to The vertex cover problem. 15/15

Similar presentations

Presentation is loading. Please wait....

OK

The Theory of NP-Completeness

The Theory of NP-Completeness

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on game theory poker Ppt on rural education and sustainable development Ppt on foundation of education Free ppt on indian culture Ppt on index of industrial production of india Ppt on reaction intermediates Ppt on event driven programming in visual basic Ppt on traffic light controller using verilog Ppt on mobile computing from iit bombay Ppt on heat treatment of steel