Download presentation

Presentation is loading. Please wait.

Published byKamryn Pallett Modified over 2 years ago

1
Problems and Their Classes Solved many problems using different algorithms For each problem - algorithm and computing time Problem classes based on computing time of best known algorithm P class NP Class

2
P Class This group consist of all problem whose computing time are polynomial time Computing time is bounded by polynomials of small degree Insertion sort O(n 2 ) Merge and Quick sort O(n logn) Binary search O(log n) Linear Class Quadratic and Cubic Class Also called as tractable (easy) problems

3
NP Class Computing of best known algorithm are non polynomial TSP using dynamic programming O(n 2 2 n ), Knapsack O(2 n/2 ) No one was has been able to develop a polynomial time algorithms for this class problems Requires vast amount of time to execute even moderate size problems Problems that can be solved using super polynomial, exponential time algorithm are called intractable (Hard )

4
NPC Theory Does not provide a method of obtaining polynomial time algorithm for problems of NP Class Nor it say that algorithms of polynomial complexity do not exist But many of the problems for which there are no known polynomial time algorithms are computationally related

5
Further Classes of Problems NP Complete (Non deterministic polynomial time complete) problems – NPC Problem can be solved in polynomial time if and only if all other NPC problems can also be solved in polynomial time NP Hard problems – if NP hard problem can be solved in polynomial time, then all NPC problems can be solved in polynomial time No NPC or NPHard problem is polynomially solvable All NP Complete problems are NP hard but some NP Hard are not NPC

6
There are many problems of NPC and NPH, focus should be on nondeterministic computations (to be defined) Relationship of these classes to nondeterministic computations together with apparent power of nondeterminism leads conclusion no NPC or NPH is polynomially solvable

7
Deterministic and Non Deterministic Algorithms Deterministic Algorithm Result of every operation is uniquely defined Agree with way programs are executed on a computer In a theoretical framework we can remove this restriction on the outcome of every operation Non Deterministic Algorithm Allow algorithm to contain operations whose outcomes are limited to specific set of possibilities Machine executing such operations are allowed to choose any one of these outcome subject to termination condition defined This leads to non deterministic Algorithm

8
Non Deterministic Algorithms Introduce new functions Choice (set S) – arbitrarily choose one element of S Failure() – signals an unsuccessful completion Success()- signals a successful completion X = choice(1,n) results in x being assigned any one of integer in the range of 1 to n, but no rule how this choice is to be made ! Failure and success – just to define a computation of algorithm and cannot be used to effect a return Whenever there is a set of choices that leads to a successful completion, then one such set of choices is always made and algorithm terminates successfully

9
Non Deterministic Algorithms NDA terminates unsuccessfully if and only if there is no set of choices leading to success signal Hence depending upon order in which choices are made – affects the successful / unsuccessful termination of NDA Computing time of Choice(), Success(),failure() is O(1) – Constant Machine capable of handling NDA is called as nondeterministic Machine (NDM) Although, NDM do not exist in practice, there are certain problems that can not be solved by deterministic algorithm.

10
Non Deterministic Search Algorithms A decision problem gives answer either 0 or 1 Search a element x in a given set A, write index else 0 J = choice (1,n); // Select form a set If A[j] = x then {write (j);success();} //write index Write(0); failure(); Computing time of this algorithm is O(1) in both cases, HOW ? Any Deterministic search algorithm requires O(n) time – Linear

11
Non Deterministic Sorting 1.Algorithm Nsort(A,N) 2.// sort n positive numbers 3.{ 4.For I = 1 to n do B[i] = 0 ; // initialize B 5.For I = 1 to n do 6.{ 7.J = choice(1,n); 8.If B[j] != 0 then failure(); 9.B[j] = A[i]; 10.} 11.For I = 1 to n-1 do // verify the order 12.If B[i] > B[i+1] then failure (); 13.Write (B); 14.Success(); 15.} In the for loop of 5 to 10 each A[i] is assigned to position in B Line 7 non deterministically identifies this position Line 8 checks whether this position is already used or not ! The order of numbers in B is some permutation of the initial order in A For loop of line no 11 and 12 verifies the B is in ascending order, Since there is always a set of choices at line no 7 for ascending order, this is a sorting algorithm of Complexity O(N) All deterministic sorting algorithms must have A complexity O(nlogn)

12
Non Deterministic Algorithms A deterministic interpretation of a non deterministic algorithm can be made by allowing unbounded parallelism in computation Each time a choice is to be made, the algorithm makes several copies of itself One copy for each possible choices, many copies are executing at the same time. First copy to reach successful completion terminates all other copies If a copy reaches to failure completion then only that copy of algorithm terminates This interpretation enable us to better understand NDA

13
Non Deterministic Machine NDM does not makes any copies of an algorithm every time choice is made NDM has ability to select a correct element from set of choices (if exists) A correct element is defined relative to a shortest sequence of choices that leads to successful completion If no sequence of choices leading to successful termination then unsuccessful termination / computation with one unit of time Machine is Fictitious, no concerns with how the machine can make a correct choice at each step

14
Definitions Decision problem - a problem having the answer either 0 or 1. Decision problem can be NPC Decision Algorithm – solves a decision problem. Gives output 1 on successful completion and 0 on unsuccessful termination Optimization Problem – problem involving the identification of an optimal value (either maximum or minimum) for a given cost function. Optimization problem may be NP Hard Satisfiability problem – find out whether a given expression is true for some assignment of truth values to the variable in that expression

15
Definitions Clique – maximal complete subgraph for a given graph, size of Clique is the number of vertices in it Reducibility – Let L1 and L2 are 2 problems. L2 can be solved in polynomial time using a deterministic algorithm. If the same algorithm can solve problem L1 in deterministic polynomial time, then L1 α L2 (L1 Reduces to L2) α is a transitive relation

16
NDA It is possible to construct NDA for which many different choices lead to completions. Ex. If numbers of Array A are equal, many different permutations will result in sorted sequence. Concern with NDA that generate unique output Successful completion if output 1 Output 0 if no sequence of choices leading to a successful completion. Output statements are implicit in signals success and failure

17
Idea of decision algorithm may appear very restrictive but, many optimization problems can reformed into decision problems with property Decision problem can be solved in polynomial time if and only if the corresponding optimization problem can In other cases, we can at least make statement that if the decision problem cannot be solved in polynomial time then the optimization problem cannot either.

18
Maximal Clique A maximal complete subgraph of a graph G(V,E) is clique. Size of clique is the number of vertices in it. Max Clique problem is an optimization problem that has to determine the size of largest Clique in G Corresponding decision problem is to determine whether G has a clique of size at least k for some give k.

19
Maximal Clique – Decision Problem Let Dclique(G,k) be a deterministic decision algorithm for the Clique decision problem Size of max clique can be found by different values of k K = n, k= n-1, k= n-2,…. Until Dclique output = 1 If time complexity of Dclique = f(n) then size of max clique can be found in time <=n.f(n) Also if size of max clique can be determined in time g(n), then the decision problem can be solved in time g(n) Max clique problem can be solved in polynomial if and only if the clique decision problem can be solved in polynomial time

20
Non Deterministic Clique Pseudocode 1.Algorithm DCK(G,n,k) 2.{ 3.S=0; // s is initially empty set 4.For i= 1to k do 5.{ 6.T = choice (1,n); 7.If t € S then failure (); 8.S = s union {t} // add t to S 9.} 10.// at this point S contains k distinct vertex indices 11.For all pairs(I,j) such that i€S, j€S and i!=j do 12.If (I,j) is not an edge of G then failure(); 13.Success() 14.} Algorithm begins by trying to form a set of k distinct vertices Tests to see whether these vertices form a complete subgraph.

21
Satisfiability problem Let x1,x2 variables and x1’,x2’ are negation Literal is either a variable or its negation Disjunctive normal form (CNF) – (x1^ x2)V(x3^x4’) AKA Sum of Product Conjunctive normal form (CNF) – (x3Vx4’)^(x1VX2’) - AKA Product of Sum Satisfiability problem is to determine whether a formula is true for some assignment of truth values to the variables.

22
Satisfiability problem 1.Algorithm eval (E,n) 2.// Determine whether the propositional formula E is satisfiable 3.For i=1 to n do // choose a truth value assignment 4.X = choice(false,true); 5.If E(x1,x2,…xn)then success(); 6.Else failure(); 7.} Algorithm terminates successfully if and only if a given propositional formula E(x1,x2,….xn) is satisfiable Algorithm proceed by simply choosing non deterministically one of the 2 n possible assignements of truth values to x1,x2,…xn and verifying that E is true for that assignment Time taken is O(n) to choose values of x1,x2,….xn plus the time needed to deterministically evaluate E for that assignment which is proportional to E

23
Relation between p, np, npc and nph Deterministic Algorithm A and input I, halting problem is to determine that whether A will stop or enter in an infinite loop. Deterministic algorithms are special case of non deterministic algorithmsWhat we do not know and what has become the most famous unsolved problem in computer science is whether P = NP or P != NP p np npc nph

24
Cook theorem Is there any single problem in NP such that if we showed it to be in P, then that would imply that P = NP? Satisfiability is in P if and only if P = NP

25
NP Hard and NPC A problem L is NP Hard if and only if Satisfiability reduces to L (Satisfiability α L) A problem is NPC if and only if L is NP hard and L € NP Only a decision problem can be NPC Optimization problems may be NPH If L1 is decision problem and L2 is optimization problem is possible L1 α L2 Ex. Knapsack decision problem reduces to knapsack optimization problem Clique decision problem reduces to Clique optimization problem

26
NP Hard and NPC Optimization problems may reduces to corresponding decision problem Optimization problems cannot be NP Complete where as decision problem can There also exist NP Hard decision problems that are not NPC

27
Halting problem of Deterministic algorithm Arbitrary deterministic algorithm A with input I ever terminates (or enters into infinite loop) This is well known undecidable problem, No algorithm (of any complexity), Clearly cannot be in NP To show Satisfiability α halting problem, construct algorithm A, whose input are propositional to formula X. X has n variables and A tries 2 n possible truth assignments and verifies X is satisfiable A stops if X is satisfiable or enters in an infinite loop

28
Halting problem of Deterministic algorithm If we had a polynomial time algorithm for halting problem then we could solve Satisfiability problem in polynomial time using Algorithm A and input X Halting problem is NP HARD NOT NP

29
Polynomially equivalence Two problems L1 and L2 are said to be polynomially equivalent if and only if L1 α L2 and L2 α L1 Let L1 is NP Hard, To show L2 as NP Hard, show L1 α L2 We know α is transitive relation, it follows if Satisfiability α L1 and L1 α L2 then Satisfiability α L2 To show that an NP HARD decision problem is NPC exhibit a polynomial time nondeterministic algorithm for it

30
CNF Satisfiability α Clique Decision Problem (CDP) Let F = 1<=i<=k Ci be a propositional formula in Conjunctive normal form (CNF) Let 1<= I <=n be the variables in F Construct a graph G=(V,E) from F, such that G has a clique of size at least k if and only if F is satisfiable If we have a polynomial time algorithm for CDP then we can obtain a polynomial time algorithm for CNF For any F, Define graph G as V = {(σ,i)|σ is literal in clause Ci} E= {(σ,i),(δ,j)|i≠j and σ≠δ’}

31
Example F=(x1 v x2 v x3)(x1’v x2’v x3’) (x1,1)(x1’,2) (x2,1)(x2’,2) (x3,1)(x3’,2) By setting x1 = true and x2’ = true F is satisfied

32
Node Cover decision problem (NCDP) A set S € V is a node cover for a graph G(V,E) if and only if all edges in E are incident to at least one vertex in S. Size of |S| of the cover is the number of vertices in S 1 2 S = {2,4} is anode cover of size 2 3 S = {1,3,5} size In NCDP, we are given a graph and integer K, determine whether G has a node cover of size K

33
CDP α NCDP Let G (V,E) and K define in instance in CDP, |V|=n Construct G’ (complement of a graph) with a node cover of size at most n-k if and only if G has a clique of size at least k GG’ G’ has node cover of {4,5} G has Clique of size 5-2 = 3 with node

34
Polynomial Reductions Problem P is reducible to Q P p Q Transforming inputs of P to inputs of Q Reducibility relation is transitive.

35
Dynamic Programming Algorithmic Analysis

36
Dynamic Programming Dynamic programming is typically applied to optimization problems. In such problem there can be many solutions. Each solution has a value, and we wish to find a solution with the optimal value.

37
Divide-and-conquer Divide-and-conquer method for algorithm design: Divide: If the input size is too large to deal with in a straightforward manner, divide the problem into two or more disjoint subproblems Conquer: conquer recursively to solve the subproblems Combine: Take the solutions to the subproblems and “merge” these solutions into a solution for the original problem

38
Dynamic programming Dynamic programming is a way of improving on inefficient divide- and-conquer algorithms. By “inefficient”, we mean that the same recursive call is made over and over. If same subproblem is solved several times, we can use table to store result of a subproblem the first time it is computed and thus never have to recompute it again. Dynamic programming is applicable when the subproblems are dependent, that is, when subproblems share subsubproblems.

39
Ex1:Assembly-line scheduling Automobiles factory with two assembly lines. Each line has the same number “n” of stations. Numbered j = 1, 2,..., n. We denote the jth station on line i (where i is 1 or 2) by S i,j. The jth station on line 1 (S 1,j ) performs the same function as the jth station on line 2 (S 2,j ). The time required at each station varies, even between stations at the same position on the two different lines, as each assembly line has different technology. time required at station S i,j is (a i,j ). There is also an entry time (e i ) for the chassis to enter assembly line i and an exit time (x i ) for the completed auto to exit assembly line i.

40
Ex1:Assembly-line scheduling After going through station S i,j, can either Job stay on same line next station is S i,j+1 no transfer cost, or job transfer to other line next station is S i+1,j+1 transfer cost from S i,j to S i+1,j+1 is t i,j ( j = 1, …, n–1) 40

41
Ex1:Assembly-line scheduling (Time between adjacent stations are nearly 0).

42
Optimal Solution Structure optimal substructure : choosing the best path to S ij. The structure of the fastest way through the factory (from the starting point) The fastest possible way to get through S i,1 (i = 1, 2) Only one way: from entry starting point to S i,1 take time is entry time (e i )

43
Step 1: Optimal Solution Structure The fastest possible way to get through S i,j (i = 1, 2) (j = 2, 3,..., n). Two choices: Stay in the same line: S i,j-1 S i,j Time is T i,j-1 + a i,j If the fastest way through S i,j is through S i,j-1, it must have taken a fastest way through S i,j-1 Transfer to other line: S i+1,j-1 S i,j Time is T i+1,j-1 + t 3-i,j-1 + a i,j

44
Optimal Solution Structure An optimal solution to a problem finding the fastest way to get through S i,j contains within it an optimal solution to sub-problems finding the fastest way to get through either S i,j-1 or S i+1,j-1

45
Example

46

47

48
Recursive Solution Define the value of an optimal solution recursively in terms of the optimal solution to sub-problems Sub-problem here finding the fastest way through station j on both lines (i=1,2) Let f i [j] be the fastest possible time to go from starting point through S i,j The fastest time to go all the way through the factory: f* x 1 and x 2 are the exit times from lines 1 and 2, respectively

49
Thank you

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google