Class Notes - 22.05.2024
Class Notes - 22.05.2024
Concept:
➢ 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, 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.
Applications
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
1. Twice-around-the-tree algorithm
• Christofides Algorithm
• Euclidean Instances
• Local Search Heuristics for TSP
Nearest-neighbor algorithm
Step 2: Repeat the following operation until all the cities have been visited: go to the
unvisited city nearest the one visited last .
Twice-around-the-tree algorithm
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.
Christofides Algorithm
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.
Example Graph
A B
C D
Step 1
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
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
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