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

Module 5 of daa

The document discusses approximation algorithms and randomized algorithms, highlighting their definitions, types, and examples. It also explores the complexity classes beyond NP and P, including PSPACE, EXPTIME, and undecidable problems, providing specific examples for each category. Key problems such as the Quantified Boolean Formula, Generalized Chess, and the Halting Problem illustrate the complexities involved.

Uploaded by

parveshgu442
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)
9 views

Module 5 of daa

The document discusses approximation algorithms and randomized algorithms, highlighting their definitions, types, and examples. It also explores the complexity classes beyond NP and P, including PSPACE, EXPTIME, and undecidable problems, providing specific examples for each category. Key problems such as the Quantified Boolean Formula, Generalized Chess, and the Halting Problem illustrate the complexities involved.

Uploaded by

parveshgu442
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/ 5

Module 5 of daa

Approximation algorithm

An approximation algorithm is an algorithm used to find near-optimal solutions to


optimization problems, especially when finding the exact solution is too time-consuming (i.e.,
NP-hard problems). These algorithms are designed to run efficiently (typically in polynomial
time) and return solutions that are provably close to the optimal.

Key Concepts

1. Approximation Ratio (or Factor):


o Measures how close the solution is to the optimal.
o For minimization problems:

Approximation Ratio=Algorithm’s solutionOptimal solution≥1\text{Approximati


on Ratio} = \frac{\text{Algorithm's solution}}{\text{Optimal solution}} \geq 1

o For maximization problems:

Approximation Ratio=Optimal solutionAlgorithm’s solution≥1\text{Approximati


on Ratio} = \frac{\text{Optimal solution}}{\text{Algorithm's solution}} \geq 1

2. Polynomial-Time Approximation Scheme (PTAS):


o For any ε > 0, it gives a solution within a factor of (1+ϵ)(1 + \epsilon) of the
optimum in time polynomial in input size (but possibly exponential in
1/ϵ1/\epsilon).
3. Fully Polynomial-Time Approximation Scheme (FPTAS):
o Like PTAS, but also polynomial in both the input size and 1/ϵ1/\epsilon.

Examples

 Vertex Cover: A 2-approximation algorithm exists (greedy approach).


 Traveling Salesman Problem (TSP):
o If the triangle inequality holds, there is a 1.5-approximation algorithm
(Christofides' algorithm).
 Knapsack Problem:
o Has an FPTAS.

Randomized algorithm
A randomized algorithm is an algorithm that uses randomness (typically through random
number generation) as part of its logic. Unlike deterministic algorithms, randomized algorithms
can produce different outputs or follow different paths on different runs, even with the same
input.

Types of Randomized Algorithms

1. Las Vegas Algorithms


o Always produce the correct result, but the running time is randomized.
o Example: Randomized QuickSort — the pivot is chosen randomly, affecting
performance but not correctness.
2. Monte Carlo Algorithms
o Have a probability of error, but the running time is guaranteed.
o Example: Miller-Rabin primality test — quickly checks if a number is prime, with
some error probability.
3. Zero-error Algorithms
o Sometimes may output "I don't know" but never give an incorrect answer.
o Often considered a mix between Monte Carlo and Las Vegas.

Why Use Randomized Algorithms?

 Simplicity: Often easier to implement and understand.


 Speed: May outperform deterministic counterparts on average.
 Robustness: Less predictable, can avoid worst-case scenarios in adversarial inputs.

Example: Randomized QuickSort


def randomized_quicksort(arr):
if len(arr) <= 1:
return arr
import random
pivot = random.choice(arr)
less = [x for x in arr if x < pivot]
equal = [x for x in arr if x == pivot]
greater = [x for x in arr if x > pivot]
return randomized_quicksort(less) + equal + randomized_quicksort(greater)

difference between np and p problems

The NP vs P question is central in computational complexity, but there are classes of problems
beyond NP and P — meaning they're harder or more general than problems that can be solved
or verified in polynomial time. Here's a structured look at some of these broader classes:
🔹 1. PSPACE (Polynomial Space)

 Definition: Problems solvable using polynomial memory, regardless of time.


 Includes: All of P and NP.
 Example: Determining the winner in a general two-player game like generalized chess or
Go (on an n×nn \times n board).
 Open Question: Is NP = PSPACE? Unknown, but believed that NP ⊂ PSPACE.

🔹 2. EXPTIME (Exponential Time)

 Definition: Problems solvable in exponential time, i.e., O(2p(n))O(2^{p(n)}) for some


polynomial p(n)p(n).
 Includes: PSPACE ⊆ EXPTIME.
 Example: Solving generalized chess or checkers from an arbitrary position.
 Believed Relationship: P ⊂ NP ⊂ PSPACE ⊂ EXPTIME (all strict, but unproven).

🔹 3. EXPSPACE (Exponential Space)

 Definition: Problems solvable in exponential space.


 Hierarchy:

P⊆NP⊆PSPACE⊆EXPTIME⊆EXPSPACE\text{P} \subseteq \text{NP} \subseteq


\text{PSPACE} \subseteq \text{EXPTIME} \subseteq \text{EXPSPACE}

🔹 4. Undecidable Problems

 Definition: Problems not solvable by any algorithm, no matter how much time or space
you allow.
 Example: Halting Problem — determining whether an arbitrary program halts.
 These are beyond even EXPSPACE.

Visualization of Classes (Informally)


Decidable Problems
┌─────────────────────────────┐
│ EXPSPACE │
│ ┌─────────────────────┐ │
│ │ EXPTIME │ │
│ │ ┌───────────────┐ │ │
│ │ │ PSPACE │ │ │
│ │ │ ┌───────────┐ │ │ │
│ │ │ │ NP │ │ │ │
│ │ │ │ ┌───────┐ │ │ │ │
│ │ │ │ │ P │ │ │ │ │
│ │ │ │ └───────┘ │ │ │ │
│ │ │ └───────────┘ │ │ │
│ │ └───────────────┘ │ │
│ └─────────────────────┘ │
└─────────────────────────────┘
Undecidable Problems

Class of problem beyond NP-p space

A problem beyond both P and NP typically falls into a harder complexity class such as
PSPACE, EXPTIME, or even undecidable problems. Here's one well-known and illustrative
example in each of these "beyond NP and P" categories:

🔹 1. PSPACE-Complete Problem: Quantified Boolean Formula (QBF)

 Problem: Given a fully quantified Boolean formula like

∃x1∀x2∃x3…ϕ(x1,x2,x3,… )\exists x_1 \forall x_2 \exists x_3 \dots \phi(x_1, x_2, x_3,
\dots)

where ϕ\phi is a Boolean formula, is it true?

 Complexity: PSPACE-complete.
 Why beyond NP?: NP can only handle existential quantifiers (like in SAT). But QBF
mixes existential and universal quantifiers, which is much more powerful and
complex.
 Application: Used in AI (e.g., game solving), formal verification, and logic.

🔹 2. EXPTIME-Complete Problem: Generalized Chess


 Problem: Given an arbitrary position on an n×nn \times n chessboard, can the first player
force a win?
 Complexity: EXPTIME-complete.
 Why beyond PSPACE?: The number of moves can be exponential in the size of the
board.
 Insight: Regular chess is in NP (due to the 50-move rule), but generalized chess
(unbounded board) is much harder.

🔹 3. Undecidable Problem: Halting Problem

 Problem: Given a program and input, will the program eventually halt or run forever?
 Complexity: Undecidable — not solvable by any Turing machine.
 Why beyond everything?: There is no algorithm that can solve this problem in general.

Summary Table

Problem Complexity Class Beyond Solvable?


QBF PSPACE-complete Beyond NP Yes
Generalized Chess EXPTIME-complete Beyond PSPACE Yes
Halting Problem Undecidable Beyond all No

You might also like