Tuesday, 28 November 2017

Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph


Code:

import java.util.Scanner;

public class NumOfSpanningBipartite
{
    private int firstSetSize;
    private int secondSetSize;

    public int numberOfSpanningTree(int firstSetSize, int secondSetSize)
    {
        this.firstSetSize = firstSetSize;
        this.secondSetSize = secondSetSize;
        return (this.firstSetSize^(this.secondSetSize - 1)) *(this.secondSetSize ^ (this.firstSetSize -1)); 
    }

    public static void main(String...arg)
    {
        int m, n;
        Scanner scanner = new Scanner(System.in);
        System.out.println("enter the size of the bipartite graph (m and n)");
        m = scanner.nextInt();
        n = scanner.nextInt();

        NumOfSpanningBipartite bipartite = new  NumOfSpanningBipartite();
        System.out.println(" the number of spanning trees are  " + bipartite.numberOfSpanningTree(m, n));
        scanner.close();
    }
}


Output:

enter the size of the bipartite graph (m and n)
2 2
 the number of spanning trees are  9



More Java Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...