0% found this document useful (0 votes)
172 views23 pages

SCS03P076Hamiltonian Path Problem

This document discusses algorithms to determine if a graph contains a Hamiltonian cycle. It defines Hamiltonian path and Hamiltonian cycle, and describes an algorithm that checks if a graph contains a Hamiltonian path first. If it does not, the graph cannot have a Hamiltonian cycle. If it does contain a Hamiltonian path, the algorithm removes edges and joins vertices to check if the modified graph contains a Hamiltonian path, which would indicate the original graph has a Hamiltonian cycle. It provides examples of graphs that do and do not contain Hamiltonian cycles based on this process.

Uploaded by

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

SCS03P076Hamiltonian Path Problem

This document discusses algorithms to determine if a graph contains a Hamiltonian cycle. It defines Hamiltonian path and Hamiltonian cycle, and describes an algorithm that checks if a graph contains a Hamiltonian path first. If it does not, the graph cannot have a Hamiltonian cycle. If it does contain a Hamiltonian path, the algorithm removes edges and joins vertices to check if the modified graph contains a Hamiltonian path, which would indicate the original graph has a Hamiltonian cycle. It provides examples of graphs that do and do not contain Hamiltonian cycles based on this process.

Uploaded by

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

Computer Science

Design and Analysis of


Algorithms
2D Animation using
JAVA

To find out whether the graph has


Hamiltonian cycle if there exists a
Hamiltonian path.

Hamiltonian Path (HP)


A Hamiltonian path is a path in an
undirected graph which visits each
vertex exactly once.

Hamiltonian cycle (HC)


A Hamiltonian cycle (or Hamiltonian
circuit) is a cycle in an undirected graph
which visits each vertex exactly once and
also returns to the starting vertex.

Aim and procedure


Aim is to show this algorithm by animation so that

it become easy to visualize what is going on with


removing edges and vertices.
Procedure:
If it doesnt contains HP:
If it doesnt have Hamiltonian Path then it will
definitely wont have HC. As every HC has HP in it.

If it contains HP :
In this case graph may have HC or may not. For
that we need to remove edge and new vertices in
the graph.

Problem Statement
Input:
A graph
Yes(If graph has HP)
No(If graph doesnt have HP)
Output:
Yes(If the graph has HC)
No(If the graph doesnt have HC)

--GRAPH

--Red line represents


HP in the Graph

Case 1: There is no HP in the Graph

Path 1

Path 2

We can see that if the graph doesnt have HP in


it then it cannot have HC in it in any case.

HP is a subset-path of HC and if there is no HP than their cannot be


HC . We saw this by the above example.

Case 2: If there exists an HP in the


graph

Procedure : Remove one edge and join the two vertic


with two newly created vertices.
Now check whether that new graph has HP
or not. If it has HP than the original graph
HC in it.

Note : We have to do this for all the edges if altering


edge we find HP than we have HC in the original grap
But if we dont find HP after trying with all edges than
the previous graph dont have HC in it.

If the Graph has HP it may have HC or not depends on the above procedure.

Example for existence of HC while there is HP

First choosing this edge

Starting from this point we will try to fi


HP in it.

Take any two vertices and join them with two new vertices

10

Path 1
Got stuck from this path
And was not able to get
HP this way.

Path 2

We find out a HP in the new graph via path 2.

11

Since we are able to find a HP in the new


graph therefore there exist a HC in the
original graph

12

Example for no existence of HC while there is HP

There is a HP in the graph but we


see that there is no HC this time.

Take any two vertices and remove the edge

13

Join them with two new ver

We are going to search for


HP in the new graph throug
this point.

14

Option 1

Option 2

Path 2

Path 1

15

Path 1

This point has now 2 options.

No HP through any further path

16

Path 2

Similarly here we have 3 options and similarly doing the above steps to find HP we
didnt reach HP.

Blue green and Red lines show the different


option we could follow to find HP but none o
them leads to HP

17

We removed this edge but here we wer


Not able to find HP in the new graph.

Similarly we need to check for all the edges and if we are not able to find HP throu
Then we will conclude that the original graph doesnt have HC

18

Trying to find HP on
removing this edge now.

19

Starting from this point

Similarly as previous example after trying every possible path we


didnt reach HP.

20

We tried for the above two edges, similarly trying for every edge we were not able to

Conclusion: After checking with all the edges, we find there doesnt exists HP there
Original graph doesnt contain HC in it.

21

Review Questions

22

CREDI
TS

Saurabh Chanderiya
07005004
Computer Science and
Engineering.
saurabhc@cse.iitb.ac.in

23

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy