0% found this document useful (0 votes)
8 views

Unit-5 DAA-2

The document covers key concepts in the design and analysis of algorithms, including the Randomized Hiring problem, Randomized Quicksort, and definitions of complexity classes such as P, NP, NP-Hard, and NP-Complete. It discusses methods for proving NP-Completeness, specifically through reductions, and provides examples of NP-Complete problems like CLIQUE, INDSET, and VERTEX-COVER. Additionally, it introduces approximation algorithms, particularly for the VERTEX-COVER problem, demonstrating a 2-approximation algorithm.

Uploaded by

Yashwanth Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Unit-5 DAA-2

The document covers key concepts in the design and analysis of algorithms, including the Randomized Hiring problem, Randomized Quicksort, and definitions of complexity classes such as P, NP, NP-Hard, and NP-Complete. It discusses methods for proving NP-Completeness, specifically through reductions, and provides examples of NP-Complete problems like CLIQUE, INDSET, and VERTEX-COVER. Additionally, it introduces approximation algorithms, particularly for the VERTEX-COVER problem, demonstrating a 2-approximation algorithm.

Uploaded by

Yashwanth Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Unit - 5

Design and Analysis of Algorithms


● Randomized Hiring problem
● Randomized Quicksort
● Definitions of P, NP, NP-Hard, NP-Complete
● Relationship between the complexity classes
● Showing a problem is NP-Complete
● CLIQUE, INDSET, VERTEX-COVER is NPC.
● Why Approximation Algorithms
● VERTEX-COVER has a polynomial time approximation algorithm
Randomized Quicksort

Best Case Running Time: O(nlogn)

Worst Case Running Time: O(n^2)

Average Case Running Time: O(nlogn)


Randomized Quicksort

To prove: Expected Running Time: O(nlogn)

This is called a Worst-case Expected-Time bound.


Let ei be the ith smallest element and ej be the jth smallest element in the array. Assume: ei < ej.

Case 1: If ei < p < ej, then ei and ej will never be compared as they fall into different partitions.

Case 2: If p = ei or p = ej, then we do compare p (say = ei) with ej.

Case 3: If p < ei < ej or ei < ej < p, then ei and ej will fall into same bucket and another pivot will be chosen.

Probability that ei and ej will be compared = 2 / (j-i+1). Hence,


Subset Sum Problem: Given N non-negative integers a1…aN and a target
sum K, the task is to decide if there is a subset having a sum equal to K.

Example: Let {5, 7, 3, 9, 1}, Target Sum: 12

Is {5,7} a solution : YES

Is {7,3,1} a solution: NO
TRUE
1. P is a subset of NP
2. NPC is a subset of NP
3. NPC is a subset of NPH

NOT KNOWN
1. NP is a subset of P
2. P = NP

If P = NP
3. P = NP = NPC is a subset of
NPH
If P is not equal to NP
4. P (intersection) NPC = empty
5. P (intersection) NPH = empty
How to show that a problem L is NP-Complete
1. Prove: L is in NP.
2. Prove: L is NP-Hard. That is, all problems in NP are poly-time reducible to L.

Statement 2 seems to be impractical since we cannot enumerate all NP


problems and reduce it to L.
Trick: Cook-Levin Theorem : SAT is NP-Complete.
This means: SAT is NP-Hard and hence Every NP problem is reducible to SAT.

If we show SAT is reducible to L, then by transitivity, Every NP problem is reducible to L.


Hence L is NP-Hard.
Using Transitivity
1. SAT is NP-Complete (Cook-Levin theorem) Proof Omitted
2. Hence, every NP problem is reducible to SAT.
3. SAT is reducible to 3SAT. Proof Omitted
4. Combining 2 and 3, 3SAT is NP-Hard.
5. We know that 3SAT is in NP and hence 3SAT is NP-Complete
6. What more? (Proof idea will be discussed for the following)
a. CLIQUE, INDSET, VERTEX-COVER are in NP.
b. 3SAT is reducible to CLIQUE
c. CLIQUE is reducible to INDSET
d. INDSET is reducible to VERTEX-COVER

Hence CLIQUE, INDSET, VERTEX-COVER are NP-Complete.


CLIQUE in a graph
Every edge is a 2-clique
Hence for a given graph G, the problem of
“Does there exists a clique of size 2 in G”
has always an YES answer
“Does there exists a clique of size 3 in G”
Yes for the depicted graph
No for ??? graph
“Does there exists a clique of size 4 in G” 23

No for the depicted graph


Size of maximum Clique is 3
First, prove that CLIQUE is in NP
It is simple to find a verifier for CLIQUE, using the nodes in the clique as
the certificate:

●1. Verify that the clique is a subgraph of the correct size


●2. Check that the graph contains edges connecting the nodes in the
clique.

●If 1 and 2 are both true, accept, otherwise reject.


Now, a polynomial time reduction from 3SAT
● We will construct a graph G based on a formula φ.
● Let k be the number of clauses in φ.
● G will have a clique of size k iff φ is satisfiable.

Construction of G
● Each clause in φ will be represented as a set of three nodes, one for each
literal.
● The nodes will all be connected, except that no nodes from the same clause
will be connected and no two nodes with contradictory labels will be connected
(i.e. x1 and ~x1 shall not share an edge)
φ=(~x1∨ x2∨ x3)
∧ (x1∨~x2 ∨
~x3) ∧ (x1 ∨ x2 x1 x2 x3
∨ x3)

~x1 x1

x2 x2

x3 x3
An example
Proof (optional)
Theorem: φ is satisfiable iff G has a k-clique:
Assume φ is satisfiable. In each clause, at least one literal is true. Select one
node which has a true literal as its label from each clause. The nodes selected
form a k-clique since the nodes are selected one from each clause. The labels
are connected since they cannot be contradictory.

(Conversely) Assume G has a k-clique. Assign each of the literals in the labels
of the clique to be true. Because nodes from the same clause are not
connected, a k-clique must visit k clauses. No contradictions will be
encountered since contradictory labels are not connected. Thus each clause
contains at least one true literal, which means that φ is satisfied.
The light grey vertices form the minimum vertex cover.

However the problem of finding vertex


cover is NP-Complete. Hence we have a
polynomial approximation algorithm
Let A be the set of edges chosen in line 4 of the algorithm. Any vertex cover must cover at least one endpoint of every
edge in A. No two edges in A share a vertex (see algorithm), so in order to cover A, the optimal solution C* must have at
least as many vertices:

| A | ≤ | C* |

Since each execution of line 4 picks an edge for which neither endpoint is yet in C and adds these two vertices to C, then
we know that

|C| = 2|A|

Therefore:

| C | ≤ 2 | C* |

That is, |C| cannot be larger than twice the optimal, so is a 2-approximation algorithm for Vertex Cover.

You might also like