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:
Display Auto-Configuration Report in Spring Boot
Converting Between an Array and a Set in Java
Biến trong java
Java – String to Reader
Toán tử trong java
“Stream has already been operated upon or closed” Exception in Java
Spring Boot - OAuth2 with JWT
Java Program to implement Associate Array
Jackson Date
Java Program to Implement Caesar Cypher
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Using the Map.Entry Java Class
Giới thiệu thư viện Apache Commons Chain
Introduction to Spring Cloud Rest Client with Netflix Ribbon
Custom JUnit 4 Test Runners
Java Program to implement Array Deque
Java Program to Implement Knapsack Algorithm
Introduction to Liquibase Rollback
Java Program to Check Whether a Weak Link i.e. Articulation Vertex Exists in a Graph
Java Program to Perform Stooge Sort
MyBatis with Spring
Mix plain text and HTML content in a mail
HttpClient with SSL
Primitive Type Streams in Java 8
Introduction to Spring Data MongoDB
Java Program to Find Location of a Point Placed in Three Dimensions Using K-D Trees
Java Program to Check the Connectivity of Graph Using DFS
Giới thiệu SOAP UI và thực hiện test Web Service
OAuth2 Remember Me with Refresh Token
Spring Cloud – Tracing Services with Zipkin
REST Web service: Basic Authentication trong Jersey 2.x
Java Program to Use the Bellman-Ford Algorithm to Find the Shortest Path