You are on page 1of 6

# 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:

## We can see that A, C and D are kings of this tournament.

A -> B || A -> D || A -> D -> C
C -> A || C -> B ||C -> B/A -> D
D -> C -> A || D -> C -> B || D -> C
The output:
4. Maximum matching of a bipartite graph can be used by network flow. A dummy
source and sink is created and the source is connected to all the elements in the x-
partite and all the elements in the y-partite are connected to the sink and the
capacities of all the edges are taken to be 1. Applying Ford-Fulkersons algorithm to
solve network flow, we can find the maximum matching of the graph.
The graph used for testing:

## The edges in red contribute to the maximum matching.

The output:
5. The Prufer Code algorithm is applied. The leaf nodes are found, eliminated and the
adjacent node is printed till there is only one edge present.
The graph used for testing is: