This Java program is to find the number of spanning trees in a Complete Bipartite graph. This can be calculated using the matrix tree theorem or Cayley’s formula.
Here is the source code of the Java program to ind the number of spanning trees in a Complete Bipartite graph. The Java program is successfully compiled and run on a Linux system. The program output is also shown below.
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();
}
}
$javac NumOfSpanningBipartite.java $java NumOfSpanningBipartite enter the size of the bipartite graph (m and n) 2 2 the number of spanning trees are 9
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
If you wish to look at all Java Programming examples, go to Java Programs.
Next Steps:
- Get Free Certificate of Merit in Java Programming
- Participate in Java Programming Certification Contest
- Become a Top Ranker in Java Programming
- Take Java Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy Programming Books
- Buy Java Books
- Practice Information Technology MCQs
- Practice Programming MCQs
- Practice BCA MCQs