Assignment 2
Assignment 2
1) Write a program for finding maximum bipartite sub-graph in a given graph. Explain
your approach with suitable test cases?
2) Write a program for solving Chinese postman problem. Explain your approach with
suitable test cases?
3) Write a Prolog code for finding all kings of a tournament. Explain your approach
with suitable test cases?
4) Write a program for finding maximum matching in a given bipartite graph. Explain
your approach with suitable test cases?
5) Write a program to generate Prufer code for a given labelled tree. Explain your
approach with suitable test cases?
Solutions
1. The vertex with the maximum degree is found out and added to the x-partite. All the
vertices adjacent to this vertex are added to the y-partite. The next vertex with the
highest degree is found out, and if it is not present in any partite, it is added to the x-
partite and all the vertices adjacent to this vertex are added to the y-partite. If that
vertex is already present in the y-partite, then the vertex with the maximum degree
adjacent to this vertex and also not present in any partite is found out and added to x-
partite and all the vertices adjacent to this vertex are added to the y-partite. This
procedure is repeated till all the vertices are covered.
The graph used for testing:
The output:
2. The Chinese Postman problem involves finding an Eulerian path. If there exists an
Eulerian path, then the shortest path to be covered by the postman is just the sum of
all lengths of edges. Else, the odd degree vertices have to be paired in such a way that
the path length is minimised. Since more than 4 odd degree vertices may result in at
least 15 different ways of pairing, this algorithm runs only on graphs with at most 4
odd degree vertices.
The graph used for testing:
Here, A and H have to be paired, and the shortest path between them is ABFH.
The output:
3. A king of a tournament is an element which can connect to all other elements
through at most two edges. The same logic is applied in the code.
The graph used is: