0% found this document useful (0 votes)
28 views6 pages

Class Notes - 22.05.2024

notes
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)
28 views6 pages

Class Notes - 22.05.2024

notes
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/ 6

UNIT – 5

NP-Complete and Approximation Algorithm

Randomized Algorithms: Concept and Applications


Randomized algorithm is just one that depends on random numbers for its
operations.

Concept:

Using random numbers to help find a solution to a problem


Using random numbers to improve a solution to a problem
For an optimization problem, a randomized algorithm gives an optimal
solution.
For a decision problem, a randomized algorithm may make mistake.

There are two main types of randomized algorithms:

• Las Vegas algorithms

• Monte Carlo algorithms

Las Vegas algorithms

➢ Las Vegas algorithms are randomized algorithms that always return the
correct answer, but the running time can vary depending on the input.

➢ An example of a Las Vegas algorithm is quick sort, where the pivot element
is chosen randomly and the expected running time is O(n log n).

Monte Carlo algorithms

➢ Monte Carlo algorithms, on the other hand, may return an incorrect answer
with a certain probability, but the running time is typically fixed.
➢ They are often used in situations where the cost of obtaining a correct answer
is very high, or where a probabilistic answer is sufficient.

➢ An example of a Monte Carlo algorithm is the Miller-Rabin primality test,


which is used to determine whether a number is prime or composite with a
certain probability.

Applications

Randomized algorithms are used in a wide range of applications, including


cryptography, machine learning, computational biology, and optimization.

Approximation Algorithm for TSP


An algorithm that returns near optimal solutions in polynomial time is known as
approximation algorithm.

Greedy Algorithms for the TSP- The simplest approximation algorithms for the
traveling salesman problem are based on the greedy technique.

* Nearest-neighbor algorithm

* Multifragment-heuristic algorithm

Minimum-Spanning-Tree Based Algorithms - Since removing an edge from a


Hamiltonian circuit yields a spanning tree, we can expect that the structure of a
minimum spanning tree provides a good basis for constructing a shortest tour
approximation.

1. Twice-around-the-tree algorithm

• Christofides Algorithm

• Euclidean Instances
• Local Search Heuristics for TSP

Nearest-neighbor algorithm

Nearest-neighbor heuristic: always go next to the nearest unvisited city.

Step 1: Choose an arbitrary city as the start.

Step 2: Repeat the following operation until all the cities have been visited: go to the
unvisited city nearest the one visited last .

Step 3: Return to the starting city.

Example refer in (Algorithm Lecture notes)

Twice-around-the-tree algorithm

Step1: Construct a minimum spanning tree of the graph corresponding to a given


instance of the traveling salesman problem.

Step2: Starting at an arbitrary vertex, perform a walk around the minimum spanning
tree recording all the vertices passed by. (This can be done by a DFS traversal.)

Step3: Scan the vertex list obtained in Step 2 and eliminate from it all repeated
occurrences of the same vertex except the starting one at the end of the list. (This
step is equivalent to making shortcuts in the walk.) The vertices remaining on the
list will form a Hamiltonian circuit, which is the output of the algorithm.

Example refer in (Algorithm Lecture notes)

Christofides Algorithm

1. Find a minimum spanning tree T

2. Let O be the set of vertices with odd degree in T. Find a minimum-cost perfect
matching M.
3. Add the set of edges of M to T. Find an Eulerian tour.

4. Shortcut the Eulerian tour to make a Hamiltonian Cycle.

Example Graph

A B

C D

Step 1

Construct Minimum Spanning Tree

(Remember form the studies:

MST- All vertices are connected by edges in minimum cost for weighted graph, then
not form the cycle)

B C D

Step 2
Find a minimum cost perfect matching, M for odd-degree vertices

A
B has single degree so odd
Hint: Degree means
B C D
C has single degree so odd
Input edges
D has Double degree so Even

E has single degree so odd


E

A has 3 degree so odd


M odd Degree

B C
A

Step 3
Add M odd degree in MST. Find Eulerian Tour

C D
B

Eulerian Tour: If all vertices have even degree that is called Eulerian Tour

The above graph is satisfied eulerian tour A has 4 degree , B has 2 degree, C has 2
degree, D has 2 degree and E has 2 degree

Step 4:
Shortcut the Eulerian tour to make a Hamiltonian Cycle.
A

B C
E

Local Search Heuristics for TSP

Start with some initial tour (e.g., nearest neighbor). On each iteration, explore the
current tour's neighborhood by exchanging a few edges in it. If the new tour is
shorter, make it the current tour; otherwise consider another edge change. If no
change yields a shorter tour, the current tour is returned as the output.

C1 C2 C1 C2

C3 C4

C3 C4

You might also like