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:
OAuth2 for a Spring REST API – Handle the Refresh Token in AngularJS
Java Program to Generate All Subsets of a Given Set in the Gray Code Order
Hướng dẫn sử dụng String Format trong Java
Java Program to Find Path Between Two Nodes in a Graph
Java Web Services – JAX-WS – SOAP
Java Program to Check Whether a Weak Link i.e. Articulation Vertex Exists in a Graph
Java Collections Interview Questions
Java Program to Solve any Linear Equation in One Variable
Spring WebClient Requests with Parameters
Java Program to Check whether Graph is a Bipartite using DFS
Java Program to Implement RoleList API
Java Program to Implement Sieve Of Atkin
Array to String Conversions
Java IO vs NIO
How to Get the Last Element of a Stream in Java?
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Converting Between an Array and a Set in Java
Guide to UUID in Java
Spring Boot Gradle Plugin
Auditing with JPA, Hibernate, and Spring Data JPA
Create Java Applet to Simulate Any Sorting Technique
Getting Started with GraphQL and Spring Boot
Java Program to Generate Random Partition out of a Given Set of Numbers or Characters
Java Program to Implement Lloyd’s Algorithm
Java Streams vs Vavr Streams
A Guide to the Java LinkedList
Java Program to Compare Binary and Sequential Search
Vector trong Java
Entity To DTO Conversion for a Spring REST API
Java Program to Implement TreeSet API
Java Program to Check if a Given Binary Tree is an AVL Tree or Not
Java Optional as Return Type