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:
Partition a List in Java
Tránh lỗi NullPointerException trong Java như thế nào?
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Java Program to Construct a Random Graph by the Method of Random Edge Selection
Java Collections Interview Questions
Java Program to Check whether Graph is Biconnected
Java – Combine Multiple Collections
Anonymous Classes in Java
Versioning a REST API
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Java Stream Filter with Lambda Expression
Guide to the Volatile Keyword in Java
Java Program to Implement Queue using Linked List
Hướng dẫn sử dụng Java Reflection
Map Serialization and Deserialization with Jackson
Java Program to Solve the 0-1 Knapsack Problem
Tiêu chuẩn coding trong Java (Coding Standards)
Exploring the New Spring Cloud Gateway
Converting Strings to Enums in Java
Deploy a Spring Boot WAR into a Tomcat Server
Java Program to Implement ArrayList API
A Guide to EnumMap
A Guide to Apache Commons Collections CollectionUtils
Spring Security Login Page with React
Java – Byte Array to Reader
Logout in an OAuth Secured Application
Phương thức tham chiếu trong Java 8 – Method References
Object cloning trong java
@Lookup Annotation in Spring
Finding the Differences Between Two Lists in Java
Java Program to Implement Radix Sort
Java Timer