SI545 VLSI CAD: Logic to Layout. Algorithms

Size: px
Start display at page:

Download "SI545 VLSI CAD: Logic to Layout. Algorithms"

Transcription

1 SI545 VLSI CAD: Logic to Layout Algorithms

2 Announcements TA for this course LeileiWang, Office hour: 1:30-:30pm, Thurs., Course page on Piazza

3 References and Copyright Slides used (Modified when necessary) Majid Sarrafzadeh, 001 Department of Computer Science, UCLA Kurt Keutzer, Dept. of EECS, UC-Berekeley Rajesh Gupta, UC-Irvine Kia Bazargan, University of Minnesota Naveed A. Sherwani, 1999

4 Computational Complexity

5 Combinatorial Optimization Problems Problems with discrete variables Examples: SORTING Given N integer numbers, write them in increasing order. KNAPSACK Given a bag of size S, and items {(s 1, v 1 ), (s, v ),..., (s n, v n )}, where s i and v i are the size and value of item i respectively, find a subset of items with maximum overall value that fit in the bag. 5

6 Graph Definition Graph: set of objects and their connections Formal definition: G = (V, E), V={v 1, v,..., v n }, E={e 1, e,..., e m } V: set of vertices (nodes), E: set of edges (links, arcs) Directed graph: e k = (v i, v j ) Undirected graph: e k ={v i, v j } Weighted graph: w: E R, w(e k ) is the weight of e k. a a e d b e d b c c 6

7 Decision Problem vs. Optimization Problem Decision problem ask for a yes or no answer Example: Hamiltonian cycle - simple cycle (no repeated vertices) that contains all nodes in the graph; TRAVELING SALESMAN. Optimization problem find optimal value of a target variable Example: Traveling salesman problem (TSP) - min-cost Hamiltonian cycle 11 Optimization problem is harder than its decision problem version

8 Algorithm An algorithm defines a procedure for solving a computational problem Examples: Quick sort, bubble sort, insert sort, heap sort Dynamic programming method for the knapsack problem 8

9 Bubble Sort for (j=1; j < N; j++) { for (i=1; i < N-j+1; i++) { if (a[i] > a[i+1]) { hold = a[i]; a[i] = a[i+1]; a[i+1] = hold; } } } e.g., initial ordering: 10, 5, 3, 8, 6, 1 9

10 [ Bubble Sort Animation Value 10 Index

11 Complexity Measure the efficiency of a algorithm Time and memory Computational complexity Time complexity, space complexity Average case, worst case Scalability (with respect to input size n) is important How does the running time of an algorithm change when the input size doubles? Function of input size (n). Examples: n +3n, n, nlog n,... Generally, large input sizes are of interest (n > 1,000 or even n > 1,000,000) 11

12 Function Growth Examples Function Growth f(n) 5n 0.1n^+n+40 n log n ^n n f(n) Function Growth 5n 0.1n^+n+40 n log n ^n n

13 Idea: Asymptotic Notions A notion that ignores the constants and describes the trend of a function for large values of the input. Definition Big-Oh notation f(n) = O(g(n)). if constants K and n 0 can be found such that: n n 0, f(n) K g(n) g is called an upper bound for f (f is of order g: f will not grow larger than g by more than a constant factor). Examples: 1/3 n = O (n ) 0.0 n + 17 n = O (n ) 13 Tractability: solvable in polynomial time Polynomial time = O(n k ), otherwise exponential

14 Asymptotic Notions (cont.) Definition (cont.) Big-Omega notation f(n) = ( g(n) ) if constants K and n 0 can be found such that: n n 0, f(n) K g(n) g is called a lower bound for f Question: If f(n)=o(g(n)), then is g(n)= (f(n))? Big-Theta notation f(n) = ( g(n) ) if g is both an upper and lower bound for f - Describes the growth of a function more accurately than O or Example: n n (n ) 4 n = (n ) 14

15 Asymptotic Notions (cont.) How to find the order of a function? Not always easy, esp. if you start from an algorithm. Focus on the dominant term 4 n n + log n n + n log(n) n! > K n > n K > log n > log log n > K What do asymptotic notations mean in practice? If algorithm A has time complexity O(n ) and algorithm B has time complexity O(n log n), then which algorithm is better? If problem P has a lower bound of (n log n), then there is NO WAY you can find an algorithm that solves the problem in O(n) time. 15

16 The Complexity Classes P vs. NP A problem s complexity = the time complexity of the most efficient possible algorithm. Problems are classified into easier and harder categories Class P: a polynomial time algorithm is known for the problem (hence, it is a tractable problem) Examples: search problem, minimum spanning tree, etc. Class NP (non-deterministic polynomial time) A decision problem Can be solved in polynomial time on a nondeterministic computer Nondeterministic: multiple possibilities available for next step in computation A solution is verifiable in polynomial time on a deterministic computer Example: TRAVELING SALESMAN (=Hamilton cycle with length k). 16 P NP Is P = NP? (Find out and become famous!)

17 NP-Complete Practically, for a problem in NP but not in P: polynomial solution not found yet (probably does not exist) exact (optimal) solution can be found using an algorithm with exponential time complexity Class NP-complete (NPC) The most difficult problems in the NP class Till now, the best algorithm for worst-case NPC problems has exponential time complexity 17

18 Examples of NPC Problems Does a graph have a Hamiltonian cycle? Hamiltonian cycle/traveling SALESMAN 3SAT: Given a Boolean expression expressed as POS with 3 literals in each sum, is it satisfiable? Example: (x + y + z)( x + y)( y + z)( x + y + z) SAT can be solved in polynomial time! Find a maximal clique in a graph Clique = set of vertices so that every pair of vertices in the set is connected by an edge (complete subgraph) Find a maximal independent set in a graph A max set of vertices so that no pair of vertices is connected VLSI fixed-outline floorplanning Bible of NP-completeness M. R. Garey and D. S. Johnson, Computers and Intractability, W. H. Freeman and Company, New York, NY,

19 NP-Hard Class NP-hard A special definition - solution not verifiable in polynomial time on a deterministic computer At least as difficult to solve as NPC Example: TSP problem (solution check O(n n!)) Most CAD problems are NPC, NP-hard, or worse Be happy with a reasonably good solution Reading material on time complexity Textbook [Ch. 4., Wang], plus Princeton slides. 19 Stephen Cook, 198 s Turing award

20 0 Algorithm Types Deterministic vs. probabilistic (or randomized) Graph algorithms Heuristics: apply heuristics to find a good, but not necessarily optimal solution Greedy algorithm Dynamic programming Branch-and-bound Simulated annealing Genetic Mathematical programming Read [Ch. 4.4, Wang] for the detailed discussion on these algorithms.

21 1 Graph Algorithms

22 Graph Representation: Adjacency List a a b d c e d b b c a d a c d e e b d a a a b d e d b b c d a c d e a e

23 Graph Representation: Adjacency Matrix a a a 0 b c d e e d b b c c d e a a a 0 b c d e e d b b c c d e

24 4 Edge/Vertex Weights in Graphs Edge weights Usually represent the cost of an edge Examples: Distance between two cities e Width of a data bus 1 Representation Adjacency matrix: instead of 0/1, keep weight Adjacency list: keep the weight in the linked list item Node weight Usually used to enforce some capacity constraint Examples: The size of gates in a circuit The delay of operations in a data dependency graph d a - 3 c a b b 5 1 *

25 Hypergraphs Hypergraph definition Similar to graphs, but edges not between pairs of vertices, but between a set of vertices Directed/undirected versions possible Just like graphs, a node can be the source (or be connected to) of multiple hyperedges Data structure?

26 6 Graph Search Algorithms Purpose: to visit all the nodes Algorithms Depth-first search Breadth-first search Topological (on directed acyclic graph) Examples B D A F E G C B E G F A D C A B G F D E C

27 Depth-First Search Algorithm struct vertex {... int marked; }; dfs ( v ) v.marked 1 print v for each (v, u) E if (u.marked!= 1) // not visited yet? dfs (u) 7 Algorithm DEPTH_FIRST_SEARCH ( V, E ) for each v V v.marked 0 // not visited yet for each v V if (v.marked == 0) dfs (v)

28 Depth-First Search Algorithm dfs ( a ) a.marked 1 print a for each (a, u) E if (u.marked!= 1) dfs (u) dfs( a )... a a a b d c b a d e d b c d a e b a c e d 8

29 Depth-First Search Algorithm u=b dfs ( a ) a.marked 1 print a for each (a, u) E if (b.marked!= 1) dfs (b) dfs( a )... dfs( b )... a a a b d c b a d e d b c d a e b a c e d 9

30 Depth-First Search Algorithm dfs ( b ) b.marked 1 print b for each (b, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( b )... a b a a b d c b a d e d b c d a e b a c e d 30

31 Depth-First Search Algorithm u=a dfs ( b ) b.marked 1 print b for each (b, u) E if (a.marked!= 1) dfs (a) dfs( a )... dfs( b )... a b a a b d c b a d e d b c d a e b a c e d 31

32 Depth-First Search Algorithm u=d dfs ( b ) b.marked 1 print b for each (b, u) E if (d.marked!= 1) dfs (d) dfs( a )... dfs( b )... dfs( d )... a b a a b d c b a d e d b c d a e b a c e d 3

33 Depth-First Search Algorithm dfs ( d ) d.marked 1 print d for each (d, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( b )... dfs( d )... a b d a a b d c b a d e d b c d a e b a c e d 33

34 Depth-First Search Algorithm u=e dfs ( d ) d.marked 1 print d for each (d, u) E if (e.marked!= 1) dfs (e) dfs( a )... dfs( b )... dfs( d )... dfs( e )... a b d a a b d c b a d e d b c d a e b a c e d 34

35 Depth-First Search Algorithm dfs ( e ) e.marked 1 print e for each (e, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( b )... dfs( d )... dfs( e )... a b d e a a b d c b a d e d b c d a e b a c e d 35

36 Depth-First Search Algorithm u=d dfs ( e ) e.marked 1 print e for each (e, u) E if (d.marked!= 1) dfs (u) dfs( a )... dfs( b )... dfs( d )... dfs( e )... a b d e a a b d c b a d e d b c d a e b a c e d 36

37 Depth-First Search Algorithm dfs ( e ) e.marked 1 print e for each (e, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( b )... dfs( d )... dfs( e )... a b d e a a b d c b a d e d b c d a e b a c e d 37

38 Depth-First Search Algorithm dfs ( d ) d.marked 1 print d for each (d, u) E if (b.marked!= 1) dfs (b) u=b,a dfs( a )... dfs( b )... dfs( d )... a b d e a a b d c b a d e d b c d a e b a c e d 38

39 Depth-First Search Algorithm dfs ( d ) d.marked 1 print d for each (d, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( b )... dfs( d )... a b d e a a b d c b a d e d b c d a e b a c e d 39

40 Depth-First Search Algorithm dfs ( b ) b.marked 1 print b for each (b, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( b )... a b d e a a b d c b a d e d b c d a e b a c e d 40

41 Depth-First Search Algorithm dfs ( a ) a.marked 1 print a for each (a, u) E if (d.marked!= 1) dfs (d) u=d dfs( a )... a b d e a a b d c b a d e d b c d a e b a c e d 41

42 Depth-First Search Algorithm dfs ( a ) a.marked 1 print a for each (a, u) E if (c.marked!= 1) dfs (c) u=c dfs( a )... dfs( c )... a b d e a a b d c b a d e d b c d a e b a c e d 4

43 Depth-First Search Algorithm dfs ( c ) c.marked 1 print c for each (c, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( c ) a b d e c a e d c b a b d c b c d e a d a e b a d

44 Depth-First Search Algorithm dfs ( c ) c.marked 1 print c for each (c, u) E if (a.marked!= 1) dfs (a) u=a dfs( a )... dfs( c ) a b d e c a e d c b a b d c b c d e a d a e b a d

45 Depth-First Search Algorithm dfs ( c ) c.marked 1 print c for each (c, u) E if (u.marked!= 1) dfs (u) dfs( a )... dfs( c ) a b d e c a e d c b a b d c b c d e a d a e b a d

46 Depth-First Search Algorithm dfs ( a ) a.marked 1 print a for each (a, u) E if (u.marked!= 1) dfs (u) dfs( a ) a b d e c a e d c b a b d c b c d e a d a e b a d

47 Breadth-First Search Algorithm bfs ( v, Q) v.marked 1 for each (v, u) E if (u.marked!= 1) // not visited yet? Q Q + u Algorithm BREADTH_FIRST_SEARCH ( V, E ) Q {v 0 } // an arbitrary node while Q!= {} v Q.pop() if (v.marked!= 1) print v bfs (v) // explore successors There is something wrong with this code. What is it? 47

48 Distance in (non-weighted) Graphs Distance d G (u,v): Length of a shortest u--v path in G. u d(u,v)= v x y d(x,y) = 48

49 Moore s Breadth-First Search Algorithm Objective: Find d(u,v) for a given pair (u,v) and find a shortest path u--v How does it work? Do BFS, and assign (w) the first time you visit a node. (w)=depth in BFS. Data structure Q a queue containing vertices to be visited (w) length of the shortest path u--w (initially ) (w) parent node of w on u--w u v 49

50 Moore s Breadth-First Search Algorithm Algorithm: 1. Initialize (w) for w u (u) 0 Q Q+u. If Q, x pop(q) else stop: no path u--v 3. (x,y) E, if (y)= (y) x (y) (x)+1 Q Q+y 4. If (v)= return to step 5. Follow (w) pointers from v to u. u v 50 E. F. Moore (1959), The shortest path through a maze. In Proceedings of the International Symposium on the Theory of Switching, Harvard University Press, pp

51 Moore s Breadth-First Search Algorithm u v v 3 v 1 v 4 v v 6 5 v 7 v 8 v 9 Q = u v 10 Algorithm: 1. Initialize (w) for w u (u) 0 Q Q+u. If Q, x pop(q) else stop: no path u--v 3. (x,y) E, if (y)= (y) x (y) (x)+1 Q Q+y 4. If (v)= return to step 5. Follow (w) pointers from v to u. Node u v 1 v v 3 v 4 v 5 v 6 v 7 v 8 v 9 v

52 Moore s Breadth-First Search Algorithm u v v 3 v 1 v 4 v v 6 5 v 7 v 8 v 9 Q = v 1, v, v 5 v 10 Algorithm: 1. Initialize (w) for w u (u) 0 Q Q+u. If Q, x pop(q) else stop: no path u--v 3. (x,y) E, if (y)= (y) x (y) (x)+1 Q Q+y 4. If (v)= return to step 5. Follow (w) pointers from v to u. Node u v 1 v v 3 v 4 v 5 v 6 v 7 v 8 v 9 v u u - - u

53 53 Moore s Breadth-First Search Algorithm u v 1 v v 3 v 4 v 5 v 6 v 7 v 8 v 9 v 10 Q = v 4, v 3, v 6, v 10 Algorithm: 1. Initialize (w) for w u (u) 0 Q Q+u. If Q, x pop(q) else stop: no path u--v 3. (x,y) E, if (y)= (y) x (y) (x)+1 Q Q+y 4. If (v)= return to step 5. Follow (w) pointers from v to u. Node u v 1 v v 3 v 4 v 5 v 6 v 7 v 8 v 9 v u u v v 1 u v v 5

54 Moore s Breadth-First Search Algorithm u v v 3 v 1 v 4 v v 6 5 v 7 v 8 v 9 Q = v 7 v 10 Algorithm: 1. Initialize (w) for w u (u) 0 Q Q+u. If Q, x pop(q) else stop: no path u--v 3. (x,y) E, if (y)= (y) x (y) (x)+1 Q Q+y 4. If (v)= return to step 5. Follow (w) pointers from v to u. Node u v 1 v v 3 v 4 v 5 v 6 v 7 v 8 v 9 v u u v v 1 u v 5 v v 5 54

55 Notes on Moore s Algorithm Time complexity? Space complexity? 55

56 Maze Routing Problem: find a connection from A to B A Obstacle B Quite useful for two pin nets, rip-up-and-reroute, etc. 56

57 Lee s Algorithm C. Y. Lee (1961), An algorithm for path connection and its applications. IRE Transactions on Electronic Computers, EC-10(3), pp

58 A more space-efficient version

59 59 Other improvements

60 Line search algorithms Reduced memory requirements Sends out a line and uses it to guide the search No guarantees on being able to find a route 60

61 Distance in Weighted Graphs Why does a simple BFS not work any more? Your locally best solution is not your globally best one First, v 1 and v will be visited =3 =u v 1 3 v u 11 =11 =u u 61 v should be revisited =3 =u v 1 3 v 11 =5 =v 1

62 Dijkstra s Algorithm Objective: Find d(u,v) for all pairs (u,v) (fixed u) and the corresponding shortest paths u--v How does it work? Start from the source, augment the set of nodes whose shortest path is found. decrease (w) from to d(u,w) as you find shorter distances to w. (w) changed accordingly. Data structure: S (w) (w) the set of nodes whose d(u,v) is found current length of the shortest path u--w current parent node of w on u w 6

63 Dijkstra s Algorithm Algorithm: 1. Initialize (v) for v u (u) 0 S {u}, v j = u. For each v S s.t. (v j,v) E If (v) > (v j ) + w(v j,v) (v) (u i ) + w(v j,v) (v) v j O(e) 3. Find m=min{ (v) v S } and (v k )==m S S {v k } O(v ) If S < V, goto step

64 Dijkstra s Algorithm - an example u v 1 10 v 5 v v 7 64 v Edges examined 14 v v 4

65 Dijkstra s Algorithm - an example u v v 5 v v 7 v v 4 updated, min picked 65 v 3

66 Dijkstra s Algorithm - an example u v v 5 v v v S Augmented 14 v v 4

67 Dijkstra s Algorithm - an example u v v 5 v v v 14 Edges examined v v 4

68 Dijkstra s Algorithm - an example u v v 5 v v 7 v v 4 updated, min picked 68 v 3

69 Dijkstra s Algorithm - an example u v v 5 v v 7 69 v S Augmented v v 4

70 Dijkstra s Algorithm - an example u v v 5 v v v Edges examined 14 5 v v 4

71 Dijkstra s Algorithm - an example u v v 5 v v 7 v v 4 updated, min picked 71 v 3

72 Dijkstra s Algorithm - an example u v v 5 v v 7 7 v S augmented v v 4

73 Dijkstra s Algorithm - an example u v v 5 v v v Edges examined 14 5 v v 4

74 Dijkstra s Algorithm - an example u v v 5 v v 7 v v 4 updated, min picked 74 v 3

75 Dijkstra s Algorithm - an example u v v 5 v v 7 75 v S augmented v v 4

76 Dijkstra s Algorithm - an example u v v 5 v v v Edges examined 14 0 v v 4

77 Dijkstra s Algorithm - an example u v v 5 v v 7 v v 4 updated, min picked 77 v 3

78 Dijkstra s Algorithm - an example u v v 5 v v 7 78 v S augmented v v 4

79 Dijkstra s Algorithm - why does it work? Proof by contradiction Suppose v is the first node being added to S such that (v) > d(u 0,v) (d(u 0,v) is the real shortest u 0 --v path) The assumption that (v) and d(u 0,v) are different, means there are different paths with lengths (v) and d(u 0,v) Consider the path that has length d(u 0,v). Let x be the first node in S on this path (v) > d(u 0,v) by assumption and d(u 0,v) (x) => (v) > (x) => contradiction (since the min value is the one added to S in each iteration) u 0 S v x S 79

80 Static Timing Analysis (STA) Finding the longest path in a general graph is NP-complete, even when edges are not weighted Polynomial for DAG (directed acyclic graphs) Topological search on a DAG In circuit graphs, static timing analysis (STA) refers to the problem of finding the max delay from the input pins of the circuit (esp nodes) to each gate Max delay of the output pins determines clock period In sequential circuits, FF input acts as output pin, FF output acts as input pin Critical path is a path with max delay among all paths In addition to the arrival time of each node, we are interested in knowing the slack of each node/edge 80

81 STA Example: Arrival Times Assumptions: All inputs arrive at time 0 All gate delays = 1 All wire delays = 0 Question: Arrival time of each gate? Circuit delay? 0 a 1 c f t i = max {t j } + d i e 1 g d 1 b 4 4 h

82 8 STA Example: Required Times Assumptions: All inputs arrive at time 0 All gate delays = 1, wire delay = 0 Clock period = 7 Question: maximum required time (RT) of each gate? (i.e., if the gate output is generated later than RT, clk period is violated) a 3 e 3 c 4 g 4 d f 6 5 b r i = min {r j -d j } 6 h

83 83 STA Example: Slack Assumptions: All inputs arrive at time 0 All gate delays = 1, wire delay = 0 Clock period = 7 Question: What is the maximum amount of delay each gate can be slower not to violate timing? -0= -0= -0= 3-0=3 5-0=5 5-0=5 a 3-1= e c 3-1= 4-= g d f 4-= 5-3= s i = r i -t i 6-1=5 b 6-4= h 7-5= 7-3=4 7-4=3 7-5=

84 STA: Issues If the delay of one gate changes, what is the time complexity of updating the slack of all nodes? How can slack be used? Maintain a list of K-most critical paths? Refer to Chapter 5 of Sachin S. Sapatnekar, Timing, Kluwer Academic Publishers, Boston, MA,

85 Another Application of Longest Paths Layout compaction Given a set of blocks, place them in the most compact way possible The D compaction problem is often solved as a sequence of 1D problems, in the x and y directions w a w b x b x a W a x a a x b b A set of such constraints represents a longest path problem 85

86 Example Horizontal constraint graph G h s Vertical constraint graph G v s 86

87 Example: negative-weight edges Suppose you need a and b to be stuck together Then, x b x a = w a In other words, x b x a w a a b x b x a w a To represent these in a longest path problem (use ), rewrite as x a x b -w a x b x a w a w a 87 a -w a b

88 Bellman-Ford Algorithm Dijkstra s doesn t work when a graph has negative edges Intuition we cannot be greedy any more on the assumption that the lengths of paths will only increase in the future Bellman-Ford algorithm detects negative cycles (returns false) or returns the shortest path-tree 88

89 Bellman-Ford Algorithm (shortest path) Bellman-Ford(G,w,s) for each vertex u V d(u) = parent(u) = NIL d(s) = 0 for i 1 to V -1 for each edge (u,v) E d(v) = min[d(v),d(u)+w(u,v)] for each edge (u,v) E do if d(u) + w(u,v) < d(v) then // negative cycle return false return true 89

90 Bellman-Ford Example s z y x t s z y x t s z y x t s z y x t -4 5

91 Bellman-Ford Example s t y x z 7 Bellman-Ford running time: ( V -1) E + E = (VE) 91

92 Minimum Spanning Tree (MST) Tree (usually undirected) Connected graph with no cycles E = V - 1 Spanning tree Connected subgraph that covers all vertices If the original graph not tree, graph has several spanning trees Minimum spanning tree Spanning tree with minimum sum of edge weights (among all spanning trees) Example: build a railway system to connect N cities, with the smallest total length of the railroad 9

93 Difference Between MST and Shortest Path Why can t Dijkstra solve the MST problem? Shortest path: min sum of edge weight to individual nodes Each node appear at most once in the shortest path MST: min sum of TOTAL edge weights that connect all vertices 93

94 Minimum Spanning Tree Algorithms Basic idea: Start from a vertex (or edge), and expand the tree, avoiding loops (i.e., add a safe edge) Pick the minimum weight edge at each step Known algorithms Prim: start from a vertex, expand the connected tree Kruskal: start with the min weight edge, add min weight edges while avoiding cycles (build a forest of small trees, merge them) 94

95 Prim s Algorithm for MST Data structure: S set of nodes added to the tree so far S set of nodes not added to the tree yet T the edges of the MST built so far (w) current length of the shortest edge (v, w) that connects w to the current tree (w) potential parent node of w in the final MST (current parent that connects w to the current tree) 95

96 Prim s Algorithm Initialize S, S and T S {u 0 }, S V \ {u 0 } // u 0 is any vertex T { } v S, (v) Initialize and for the vertices adjacent to u 0 For each v S s.t. (u 0,v) E, (v) w((u 0,v)) (v) u 0 While (S!= ) Find u S, s.t. v S, (u) (v) S S {u}, S S \ {u}, T T { ( (u), u) } For each v s.t. (u, v) E, If (v) > w((u,v)) then (v) w((u,v)) (v) u 96

97 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1 } Node v 1 v v 3 v 4 v v 1 v 1 v 1-97

98 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1 } Node v 1 v v 3 v 4 v v 1 v 1 v 1-98

99 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v } Node v 1 v v 3 v 4 v v 1 v 1 v 1-99

100 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v } Node v 1 v v 3 v 4 v v 1 v v v 100

101 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v } Node v 1 v v 3 v 4 v v 1 v v v 101

102 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v, v 3 } Node v 1 v v 3 v 4 v v 1 v v v 10

103 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v, v 3 } Node v 1 v v 3 v 4 v v 1 v v 3 v 3 103

104 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v, v 3 } Node v 1 v v 3 v 4 v v 1 v v 3 v 3 104

105 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v, v 3, v 4 } Node v 1 v v 3 v 4 v v 1 v v 3 v 3 105

106 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v, v 3, v 4 } Node v 1 v v 3 v 4 v v 1 v v 3 v 3 106

107 Prim s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {v 1, v, v 3, v 4, v 5 } Node v 1 v v 3 v 4 v v 1 v v 3 v 3 107

108 Kruskal s algorithm S = {}, S = E Sort S in nondecreasing order of weights While S {} For each edge (u,v) S in sorted order S = S \ (u,v) If (u,v) does not create a cycle with the edges in S S = S (u,v) 108

109 Kruskal s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {} 109

110 Kruskal s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {(v,v 3 )} 110

111 Kruskal s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {(v,v 3 ), (v 3,v 4 )} 111

112 Kruskal s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {(v,v 3 ), (v 3,v 4 ), (v 3,v 5 )} 11

113 Kruskal s Algorithm Example v 1 5 v 1 4 v 3 v v 4 S = {(v,v 3 ), (v 3,v 4 ), (v 3,v 5 ),(v,v 1 )} 113

114 Other Graph Algorithms of Interest... Min-cut partitioning Graph coloring Maximum clique, independent set Steiner tree [ 114

115 115 Dynamic Programming

116 Dynamic Programming Read the first two examples in the document written by Michael A. Trick see the Useful Links slide Knapsack problem Given N discrete items of size s i and value v i, how to fill a knapsack of size M to get the maximum value? There is only one of each item that can be either taken in whole or left out. 116

117 Dynamic Programming: Knapsack Partial solution constructed for items 1..(i-1) for knapsack sizes from 0..M (call this array A) i M-1 M c 0 c 1 c c M-1 c M For each knapsack size, how to extend the solution from 1..(i-1) to include i? Option 1: do not take item i w Option : take item i w-s i w i-1 c w i-1 i c w i c w-si +v i 117

118 Example of Knapsack i s i v i M=10 1

119 119 Mathematical Programming

120 10 General Form

121 11 ILP Example

122 1 Branch and Bound

123 13 Convex Optimization

124 Useful Links Books on STL and templates (thanks to Arvind U of M for suggesting thebooks) : Nicolai M. Josuttis, The C++ Standard Library: A Tutorial and Reference, Addison-Wesley, 1999, ISBN: David Vanevoorde and Nicolai M. Josuttis, C++ Templates, the Complete Guide, Addison- Wesley, 003, ISBN: Time Complexity and Asymptotic Notations Asymptotic bounds: definitions and theorems /asymptotic.html CMSC 341 (at CSEE/UMBC) Lecture oticanalysis.ppt Michael A. Trick, A Tutorial on Dynamic Programming, 14

125 To Read Further (Chapter 4) Heuristic algorithms Greedy Branch-and-Bound Simulated Annealing Genetic Algorithms Mathematical programming Linear programming (LP) Integer LP Convex optimization 15

126 Good References on Algorithms

ICS 252 Introduction to Computer Design

ICS 252 Introduction to Computer Design ICS 252 fall 2006 Eli Bozorgzadeh Computer Science Department-UCI References and Copyright Textbooks referred [Mic94] G. De Micheli Synthesis and Optimization of Digital Circuits McGraw-Hill, 1994. [CLR90]

More information

Unit 1A: Computational Complexity

Unit 1A: Computational Complexity Unit 1A: Computational Complexity Course contents: Computational complexity NP-completeness Algorithmic Paradigms Readings Chapters 3, 4, and 5 Unit 1A 1 O: Upper Bounding Function Def: f(n)= O(g(n)) if

More information

VIII. NP-completeness

VIII. NP-completeness VIII. NP-completeness 1 / 15 NP-Completeness Overview 1. Introduction 2. P and NP 3. NP-complete (NPC): formal definition 4. How to prove a problem is NPC 5. How to solve a NPC problem: approximate algorithms

More information

P, NP, NP-Complete, and NPhard

P, NP, NP-Complete, and NPhard P, NP, NP-Complete, and NPhard Problems Zhenjiang Li 21/09/2011 Outline Algorithm time complicity P and NP problems NP-Complete and NP-Hard problems Algorithm time complicity Outline What is this course

More information

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch] NP-Completeness Andreas Klappenecker [based on slides by Prof. Welch] 1 Prelude: Informal Discussion (Incidentally, we will never get very formal in this course) 2 Polynomial Time Algorithms Most of the

More information

NP-Completeness. NP-Completeness 1

NP-Completeness. NP-Completeness 1 NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979. NP-Completeness 1 General Problems, Input Size and

More information

Theory of Computation Chapter 1: Introduction

Theory of Computation Chapter 1: Introduction Theory of Computation Chapter 1: Introduction Guan-Shieng Huang Sep. 20, 2006 Feb. 9, 2009 0-0 Text Book Computational Complexity, by C. H. Papadimitriou, Addison-Wesley, 1994. 1 References Garey, M.R.

More information

CS/COE

CS/COE CS/COE 1501 www.cs.pitt.edu/~nlf4/cs1501/ P vs NP But first, something completely different... Some computational problems are unsolvable No algorithm can be written that will always produce the correct

More information

Limitations of Algorithm Power

Limitations of Algorithm Power Limitations of Algorithm Power Objectives We now move into the third and final major theme for this course. 1. Tools for analyzing algorithms. 2. Design strategies for designing algorithms. 3. Identifying

More information

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P Easy Problems vs. Hard Problems CSE 421 Introduction to Algorithms Winter 2000 NP-Completeness (Chapter 11) Easy - problems whose worst case running time is bounded by some polynomial in the size of the

More information

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20 NP-complete problems CSE 101: Design and Analysis of Algorithms Lecture 20 CSE 101: Design and analysis of algorithms NP-complete problems Reading: Chapter 8 Homework 7 is due today, 11:59 PM Tomorrow

More information

NP-Completeness. Until now we have been designing algorithms for specific problems

NP-Completeness. Until now we have been designing algorithms for specific problems NP-Completeness 1 Introduction Until now we have been designing algorithms for specific problems We have seen running times O(log n), O(n), O(n log n), O(n 2 ), O(n 3 )... We have also discussed lower

More information

1. Introduction Recap

1. Introduction Recap 1. Introduction Recap 1. Tractable and intractable problems polynomial-boundness: O(n k ) 2. NP-complete problems informal definition 3. Examples of P vs. NP difference may appear only slightly 4. Optimization

More information

Correctness of Dijkstra s algorithm

Correctness of Dijkstra s algorithm Correctness of Dijkstra s algorithm Invariant: When vertex u is deleted from the priority queue, d[u] is the correct length of the shortest path from the source s to vertex u. Additionally, the value d[u]

More information

Introduction to Complexity Theory

Introduction to Complexity Theory Introduction to Complexity Theory Read K & S Chapter 6. Most computational problems you will face your life are solvable (decidable). We have yet to address whether a problem is easy or hard. Complexity

More information

Data Structures in Java

Data Structures in Java Data Structures in Java Lecture 21: Introduction to NP-Completeness 12/9/2015 Daniel Bauer Algorithms and Problem Solving Purpose of algorithms: find solutions to problems. Data Structures provide ways

More information

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9 1 Computational Complexity and Intractability: An Introduction to the Theory of NP Chapter 9 2 Objectives Classify problems as tractable or intractable Define decision problems Define the class P Define

More information

IS 709/809: Computational Methods in IS Research Fall Exam Review

IS 709/809: Computational Methods in IS Research Fall Exam Review IS 709/809: Computational Methods in IS Research Fall 2017 Exam Review Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Exam When: Tuesday (11/28) 7:10pm

More information

P, NP, NP-Complete. Ruth Anderson

P, NP, NP-Complete. Ruth Anderson P, NP, NP-Complete Ruth Anderson A Few Problems: Euler Circuits Hamiltonian Circuits Intractability: P and NP NP-Complete What now? Today s Agenda 2 Try it! Which of these can you draw (trace all edges)

More information

CS 350 Algorithms and Complexity

CS 350 Algorithms and Complexity CS 350 Algorithms and Complexity Winter 2019 Lecture 15: Limitations of Algorithmic Power Introduction to complexity theory Andrew P. Black Department of Computer Science Portland State University Lower

More information

NP-Complete Problems. More reductions

NP-Complete Problems. More reductions NP-Complete Problems More reductions Definitions P: problems that can be solved in polynomial time (typically in n, size of input) on a deterministic Turing machine Any normal computer simulates a DTM

More information

CS 350 Algorithms and Complexity

CS 350 Algorithms and Complexity 1 CS 350 Algorithms and Complexity Fall 2015 Lecture 15: Limitations of Algorithmic Power Introduction to complexity theory Andrew P. Black Department of Computer Science Portland State University Lower

More information

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016) FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016) The final exam will be on Thursday, May 12, from 8:00 10:00 am, at our regular class location (CSI 2117). It will be closed-book and closed-notes, except

More information

CSC 421: Algorithm Design & Analysis. Spring 2018

CSC 421: Algorithm Design & Analysis. Spring 2018 CSC 421: Algorithm Design & Analysis Spring 2018 Complexity & Computability complexity theory tractability, decidability P vs. NP, Turing machines NP-complete, reductions approximation algorithms, genetic

More information

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016 University of Toronto Department of Electrical and Computer Engineering Final Examination ECE 345 Algorithms and Data Structures Fall 2016 Print your first name, last name, UTORid, and student number neatly

More information

Algorithms. Grad Refresher Course 2011 University of British Columbia. Ron Maharik

Algorithms. Grad Refresher Course 2011 University of British Columbia. Ron Maharik Algorithms Grad Refresher Course 2011 University of British Columbia Ron Maharik maharik@cs.ubc.ca About this talk For those incoming grad students who Do not have a CS background, or Have a CS background

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 25 NP Completeness Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 NP-Completeness Some

More information

1.1 P, NP, and NP-complete

1.1 P, NP, and NP-complete CSC5160: Combinatorial Optimization and Approximation Algorithms Topic: Introduction to NP-complete Problems Date: 11/01/2008 Lecturer: Lap Chi Lau Scribe: Jerry Jilin Le This lecture gives a general introduction

More information

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University Algorithms NP -Complete Problems Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr The Class P Definition 13.2 Polynomially bounded An algorithm is said to be polynomially bounded if its worst-case

More information

NP-completeness. Chapter 34. Sergey Bereg

NP-completeness. Chapter 34. Sergey Bereg NP-completeness Chapter 34 Sergey Bereg Oct 2017 Examples Some problems admit polynomial time algorithms, i.e. O(n k ) running time where n is the input size. We will study a class of NP-complete problems

More information

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1 CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY E. Amaldi Foundations of Operations Research Politecnico di Milano 1 Goal: Evaluate the computational requirements (this course s focus: time) to solve

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 21 Single-Source Shortest Paths Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Single-Source

More information

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees , 2009 Lecture 5: Shortest Paths & Spanning Trees University of Twente m.uetz@utwente.nl wwwhome.math.utwente.nl/~uetzm/dw/ Shortest Path Problem "#$%&'%()*%"()$#+,&- Given directed "#$%&'()*+,%+('-*.#/'01234564'.*,'7+"-%/8',&'5"4'84%#3

More information

Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions

Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions Reduction Reductions Problem X reduces to problem Y if given a subroutine for Y, can solve X. Cost of solving X = cost of solving Y + cost of reduction. May call subroutine for Y more than once. Ex: X

More information

CS 4407 Algorithms Lecture: Shortest Path Algorithms

CS 4407 Algorithms Lecture: Shortest Path Algorithms CS 440 Algorithms Lecture: Shortest Path Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Outline Shortest Path Problem General Lemmas and Theorems. Algorithms Bellman-Ford

More information

Polynomial-time Reductions

Polynomial-time Reductions Polynomial-time Reductions Disclaimer: Many denitions in these slides should be taken as the intuitive meaning, as the precise meaning of some of the terms are hard to pin down without introducing the

More information

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer Science University of Virginia www.cs.virginia.edu/~njb2b/theory

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18 20.1 Introduction Definition 20.1.1 We say that an algorithm runs in polynomial time if its running

More information

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA. Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA NP Completeness Susmita Sur-Kolay Advanced Computing and Microelectronics Unit

More information

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths Matroids Shortest Paths Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths Marc Uetz University of Twente m.uetz@utwente.nl Lecture 2: sheet 1 / 25 Marc Uetz Discrete Optimization Matroids

More information

Shortest Path Algorithms

Shortest Path Algorithms Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Single Source Shortest Path 2 Single Source Shortest Path Given: a directed or undirected graph G = (V,E) a source node

More information

More on NP and Reductions

More on NP and Reductions Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 501 Advanced Data

More information

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1 NP CS 320, Fall 2017 Dr. Geri Georg, Instructor georg@colostate.edu 320 NP 1 NP Complete A class of problems where: No polynomial time algorithm has been discovered No proof that one doesn t exist 320

More information

Graph Theory and Optimization Computational Complexity (in brief)

Graph Theory and Optimization Computational Complexity (in brief) Graph Theory and Optimization Computational Complexity (in brief) Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR 7271, Sophia Antipolis, France September 2015 N. Nisse Graph Theory

More information

Analysis of Algorithms. Unit 5 - Intractable Problems

Analysis of Algorithms. Unit 5 - Intractable Problems Analysis of Algorithms Unit 5 - Intractable Problems 1 Intractable Problems Tractable Problems vs. Intractable Problems Polynomial Problems NP Problems NP Complete and NP Hard Problems 2 In this unit we

More information

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35.

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35. NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979. NP-Completeness 1 General Problems, Input Size and

More information

ECS122A Handout on NP-Completeness March 12, 2018

ECS122A Handout on NP-Completeness March 12, 2018 ECS122A Handout on NP-Completeness March 12, 2018 Contents: I. Introduction II. P and NP III. NP-complete IV. How to prove a problem is NP-complete V. How to solve a NP-complete problem: approximate algorithms

More information

NP Complete Problems. COMP 215 Lecture 20

NP Complete Problems. COMP 215 Lecture 20 NP Complete Problems COMP 215 Lecture 20 Complexity Theory Complexity theory is a research area unto itself. The central project is classifying problems as either tractable or intractable. Tractable Worst

More information

Graduate Algorithms CS F-21 NP & Approximation Algorithms

Graduate Algorithms CS F-21 NP & Approximation Algorithms Graduate Algorithms CS673-2016F-21 NP & Approximation Algorithms David Galles Department of Computer Science University of San Francisco 21-0: Classes of Problems Consider three problem classes: Polynomial

More information

CS 583: Algorithms. NP Completeness Ch 34. Intractability

CS 583: Algorithms. NP Completeness Ch 34. Intractability CS 583: Algorithms NP Completeness Ch 34 Intractability Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time? Standard working

More information

Computational Complexity

Computational Complexity Computational Complexity Problems, instances and algorithms Running time vs. computational complexity General description of the theory of NP-completeness Problem samples 1 Computational Complexity What

More information

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes Analysis of Algorithms Single Source Shortest Path Andres Mendez-Vazquez November 9, 01 1 / 108 Outline 1 Introduction Introduction and Similar Problems General Results Optimal Substructure Properties

More information

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness Marc Uetz University of Twente m.uetz@utwente.nl Lecture 9: sheet 1 / 31 Marc Uetz Discrete Optimization Outline 1 N P and co-n P 2 N P-completeness

More information

NP Completeness and Approximation Algorithms

NP Completeness and Approximation Algorithms Winter School on Optimization Techniques December 15-20, 2016 Organized by ACMU, ISI and IEEE CEDA NP Completeness and Approximation Algorithms Susmita Sur-Kolay Advanced Computing and Microelectronic

More information

Problem Complexity Classes

Problem Complexity Classes Problem Complexity Classes P, NP, NP-Completeness and Complexity of Approximation Joshua Knowles School of Computer Science The University of Manchester COMP60342 - Week 2 2.15, March 20th 2015 In This

More information

Spring Lecture 21 NP-Complete Problems

Spring Lecture 21 NP-Complete Problems CISC 320 Introduction to Algorithms Spring 2014 Lecture 21 NP-Complete Problems 1 We discuss some hard problems: how hard? (computational complexity) what makes them hard? any solutions? Definitions Decision

More information

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Limitations of Algorithms We conclude with a discussion of the limitations of the power of algorithms. That is, what kinds

More information

Contents Lecture 4. Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression

Contents Lecture 4. Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression Contents Lecture 4 Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression Jonas Skeppstedt (jonasskeppstedt.net) Lecture 4 2018

More information

Lecture 4: NP and computational intractability

Lecture 4: NP and computational intractability Chapter 4 Lecture 4: NP and computational intractability Listen to: Find the longest path, Daniel Barret What do we do today: polynomial time reduction NP, co-np and NP complete problems some examples

More information

CMSC 441: Algorithms. NP Completeness

CMSC 441: Algorithms. NP Completeness CMSC 441: Algorithms NP Completeness Intractable & Tractable Problems Intractable problems: As they grow large, we are unable to solve them in reasonable time What constitutes reasonable time? Standard

More information

1 Primals and Duals: Zero Sum Games

1 Primals and Duals: Zero Sum Games CS 124 Section #11 Zero Sum Games; NP Completeness 4/15/17 1 Primals and Duals: Zero Sum Games We can represent various situations of conflict in life in terms of matrix games. For example, the game shown

More information

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11 Undirected Graphs Undirected graph. G = (V, E) V = nodes. E = edges between pairs of nodes. Captures pairwise relationship between objects. Graph size parameters: n = V, m = E. V = {, 2, 3,,,, 7, 8 } E

More information

Algorithm Design Strategies V

Algorithm Design Strategies V Algorithm Design Strategies V Joaquim Madeira Version 0.0 October 2016 U. Aveiro, October 2016 1 Overview The 0-1 Knapsack Problem Revisited The Fractional Knapsack Problem Greedy Algorithms Example Coin

More information

Algorithms Design & Analysis. Approximation Algorithm

Algorithms Design & Analysis. Approximation Algorithm Algorithms Design & Analysis Approximation Algorithm Recap External memory model Merge sort Distribution sort 2 Today s Topics Hard problem Approximation algorithms Metric traveling salesman problem A

More information

NP-Completeness. Subhash Suri. May 15, 2018

NP-Completeness. Subhash Suri. May 15, 2018 NP-Completeness Subhash Suri May 15, 2018 1 Computational Intractability The classical reference for this topic is the book Computers and Intractability: A guide to the theory of NP-Completeness by Michael

More information

Example: Fib(N) = Fib(N-1) + Fib(N-2), Fib(1) = 0, Fib(2) = 1

Example: Fib(N) = Fib(N-1) + Fib(N-2), Fib(1) = 0, Fib(2) = 1 Algorithm Analysis Readings: Chapter 1.6-1.7. How can we determine if we have an efficient algorithm? Criteria: Does it meet specification/work correctly? Is it understandable/maintainable/simple? How

More information

Informatique Fondamentale IMA S8

Informatique Fondamentale IMA S8 Informatique Fondamentale IMA S8 Cours 4 : graphs, problems and algorithms on graphs, (notions of) NP completeness Laure Gonnord http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@polytech-lille.fr Université

More information

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005 Algorithms and Complexity Theory Chapter 8: Introduction to Complexity Jules-R Tapamo Computer Science - Durban - September 2005 Contents 1 Introduction 2 1.1 Dynamic programming...................................

More information

Lecture 18: P & NP. Revised, May 1, CLRS, pp

Lecture 18: P & NP. Revised, May 1, CLRS, pp Lecture 18: P & NP Revised, May 1, 2003 CLRS, pp.966-982 The course so far: techniques for designing efficient algorithms, e.g., divide-and-conquer, dynamic-programming, greedy-algorithms. What happens

More information

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle Directed Hamiltonian Cycle Chapter 8 NP and Computational Intractability Claim. G has a Hamiltonian cycle iff G' does. Pf. Suppose G has a directed Hamiltonian cycle Γ. Then G' has an undirected Hamiltonian

More information

Geometric Steiner Trees

Geometric Steiner Trees Geometric Steiner Trees From the book: Optimal Interconnection Trees in the Plane By Marcus Brazil and Martin Zachariasen Part 3: Computational Complexity and the Steiner Tree Problem Marcus Brazil 2015

More information

Complexity, P and NP

Complexity, P and NP Complexity, P and NP EECS 477 Lecture 21, 11/26/2002 Last week Lower bound arguments Information theoretic (12.2) Decision trees (sorting) Adversary arguments (12.3) Maximum of an array Graph connectivity

More information

Chapter 34: NP-Completeness

Chapter 34: NP-Completeness Graph Algorithms - Spring 2011 Set 17. Lecturer: Huilan Chang Reference: Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 2nd Edition, The MIT Press. Chapter 34: NP-Completeness 2. Polynomial-time

More information

Computational Complexity

Computational Complexity Computational Complexity Algorithm performance and difficulty of problems So far we have seen problems admitting fast algorithms flow problems, shortest path, spanning tree... and other problems for which

More information

Introduction. Pvs.NPExample

Introduction. Pvs.NPExample Introduction Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 09 NP-Completeness (Chapter 34) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu I

More information

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 8.5 Sequencing Problems Basic genres.! Packing problems: SET-PACKING,

More information

Notes for Lecture 21

Notes for Lecture 21 U.C. Berkeley CS170: Intro to CS Theory Handout N21 Professor Luca Trevisan November 20, 2001 Notes for Lecture 21 1 Tractable and Intractable Problems So far, almost all of the problems that we have studied

More information

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 501 Advanced Data

More information

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014 Department of Computer Science Virginia Tech Blacksburg, Virginia Copyright c 2014 by Clifford A. Shaffer : Theory of Algorithms Title page : Theory of Algorithms Clifford A. Shaffer Spring 2014 Clifford

More information

from notes written mostly by Dr. Matt Stallmann: All Rights Reserved

from notes written mostly by Dr. Matt Stallmann: All Rights Reserved CSC 505, Fall 000: Week 0 Objectives: understand problem complexity and classes defined by it understand relationships among decision, witness, evaluation, and optimization problems understand what it

More information

A Working Knowledge of Computational Complexity for an Optimizer

A Working Knowledge of Computational Complexity for an Optimizer A Working Knowledge of Computational Complexity for an Optimizer ORF 363/COS 323 Instructor: Amir Ali Ahmadi 1 Why computational complexity? What is computational complexity theory? It s a branch of mathematics

More information

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University NP-Completeness CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Hard Graph Problems Hard means no known solutions with

More information

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter 2006 NP-Completeness (Chapter 8) Given positive integers a, b, c Question 1: does there exist a positive integer x such that

More information

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM 8. INTRACTABILITY I poly-time reductions packing and covering problems constraint satisfaction problems sequencing problems partitioning problems graph coloring numerical problems Lecture slides by Kevin

More information

CS 5114: Theory of Algorithms

CS 5114: Theory of Algorithms CS 5114: Theory of Algorithms Clifford A. Shaffer Department of Computer Science Virginia Tech Blacksburg, Virginia Spring 2014 Copyright c 2014 by Clifford A. Shaffer CS 5114: Theory of Algorithms Spring

More information

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof T-79.5103 / Autumn 2006 NP-complete problems 1 NP-COMPLETE PROBLEMS Characterizing NP Variants of satisfiability Graph-theoretic problems Coloring problems Sets and numbers Pseudopolynomial algorithms

More information

Algorithms: Lecture 12. Chalmers University of Technology

Algorithms: Lecture 12. Chalmers University of Technology Algorithms: Lecture 1 Chalmers University of Technology Today s Topics Shortest Paths Network Flow Algorithms Shortest Path in a Graph Shortest Path Problem Shortest path network. Directed graph G = (V,

More information

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm Outline 1 NP-Completeness Theory 2 Limitation of Computation 3 Examples 4 Decision Problems 5 Verification Algorithm 6 Non-Deterministic Algorithm 7 NP-Complete Problems c Hu Ding (Michigan State University)

More information

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions Summary of the previous lecture Recall that we mentioned the following topics: P: is the set of decision problems (or languages) that are solvable in polynomial time. NP: is the set of decision problems

More information

Nondeterministic Polynomial Time

Nondeterministic Polynomial Time Nondeterministic Polynomial Time 11/1/2016 Discrete Structures (CS 173) Fall 2016 Gul Agha Slides based on Derek Hoiem, University of Illinois 1 2016 CS Alumni Awards Sohaib Abbasi (BS 78, MS 80), Chairman

More information

Lecture 14 - P v.s. NP 1

Lecture 14 - P v.s. NP 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) February 27, 2018 Lecture 14 - P v.s. NP 1 In this lecture we start Unit 3 on NP-hardness and approximation

More information

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs Computational Complexity IE 496 Lecture 6 Dr. Ted Ralphs IE496 Lecture 6 1 Reading for This Lecture N&W Sections I.5.1 and I.5.2 Wolsey Chapter 6 Kozen Lectures 21-25 IE496 Lecture 6 2 Introduction to

More information

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem? Admin Two more assignments No office hours on tomorrow NP-COMPLETE PROBLEMS Run-time analysis Tractable vs. intractable problems We ve spent a lot of time in this class putting algorithms into specific

More information

Essential facts about NP-completeness:

Essential facts about NP-completeness: CMPSCI611: NP Completeness Lecture 17 Essential facts about NP-completeness: Any NP-complete problem can be solved by a simple, but exponentially slow algorithm. We don t have polynomial-time solutions

More information

Computational complexity theory

Computational complexity theory Computational complexity theory Introduction to computational complexity theory Complexity (computability) theory deals with two aspects: Algorithm s complexity. Problem s complexity. References S. Cook,

More information

Bounds on the Traveling Salesman Problem

Bounds on the Traveling Salesman Problem Bounds on the Traveling Salesman Problem Sean Zachary Roberson Texas A&M University MATH 613, Graph Theory A common routing problem is as follows: given a collection of stops (for example, towns, stations,

More information

Agenda. What is a complexity class? What are the important complexity classes? How do you prove an algorithm is in a certain class

Agenda. What is a complexity class? What are the important complexity classes? How do you prove an algorithm is in a certain class Complexity Agenda What is a complexity class? What are the important complexity classes? How do you prove an algorithm is in a certain class Complexity class A complexity class is a set All problems within

More information

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)} Preliminaries Graphs G = (V, E), V : set of vertices E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) 1 2 3 5 4 V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)} 1 Directed Graph (Digraph)

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 18 Prof. Erik Demaine Negative-weight cycles Recall: If a graph G = (V, E) contains a negativeweight cycle, then some shortest paths may not exist.

More information