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 Angular
Sử dụng JDBC API thực thi câu lệnh truy vấn dữ liệu
Java CyclicBarrier vs CountDownLatch
Java Program to Test Using DFS Whether a Directed Graph is Weakly Connected or Not
Using a Custom Spring MVC’s Handler Interceptor to Manage Sessions
A Guide to the ViewResolver in Spring MVC
String Initialization in Java
Biến trong java
Guide to Mustache with Spring Boot
JUnit5 @RunWith
Java Program to Find Second Smallest of n Elements with Given Complexity Constraint
Creating a Web Application with Spring 5
Netflix Archaius with Various Database Configurations
Làm thế nào tạo instance của một class mà không gọi từ khóa new?
Java Program to Represent Graph Using Adjacency Matrix
Java Program to Implement Stack using Linked List
REST Web service: Basic Authentication trong Jersey 2.x
Java Program to Find the Vertex Connectivity of a Graph
Giới thiệu luồng vào ra (I/O) trong Java
Java Program to Implement Double Ended Queue
Java Stream Filter with Lambda Expression
Java Program to Implement Shell Sort
Từ khóa static và final trong java
Jackson – Decide What Fields Get Serialized/Deserialized
Serverless Functions with Spring Cloud Function
Lập trình đa luồng trong Java (Java Multi-threading)
Đồng bộ hóa các luồng trong Java
Spring NoSuchBeanDefinitionException
An Intro to Spring Cloud Security
Thao tác với tập tin và thư mục trong Java
Hướng dẫn sử dụng Java Annotation
Java Program to Implement Hash Tables Chaining with Doubly Linked Lists