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
Related posts:
Java Program to Check Whether an Undirected Graph Contains a Eulerian Cycle
Java Program to Implement Bucket Sort
Java Program to Find the Shortest Path from Source Vertex to All Other Vertices in Linear Time
Java InputStream to String
Java Program to Implement Rolling Hash
Java Program to Solve Tower of Hanoi Problem using Stacks
Converting a List to String in Java
New Features in Java 13
Java Program to Implement TreeSet API
Hướng dẫn Java Design Pattern – Composite
Java Program to implement Priority Queue
The “final” Keyword in Java
Java Program to Perform Right Rotation on a Binary Search Tree
Java – Reader to Byte Array
Một số tính năng mới về xử lý ngoại lệ trong Java 7
Custom Thread Pools In Java 8 Parallel Streams
Java Program to Implement Floyd-Warshall Algorithm
Copy a List to Another List in Java
List Interface trong Java
Lớp HashMap trong Java
Sort a HashMap in Java
Spring Webflux and CORS
Java Program to Implement Tarjan Algorithm
New Features in Java 10
Java Program to Give an Implementation of the Traditional Chinese Postman Problem
Chuyển đổi giữa các kiểu dữ liệu trong Java
Java Program to Search for an Element in a Binary Search Tree
Java Program to Implement Rope
Guide to CountDownLatch in Java
Redirect to Different Pages after Login with Spring Security
Lập trình mạng với java
Java Program to Implement Ternary Search Algorithm