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:
OAuth 2.0 Resource Server With Spring Security 5
Java Program to Implement Max-Flow Min-Cut Theorem
Getting Started with GraphQL and Spring Boot
Java Program to Implement ConcurrentLinkedQueue API
Java Program to Solve any Linear Equations
Java Program to Implement VList
Java Program to Implement vector
Java Program to Implement LinkedBlockingQueue API
Java Program to Implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for Elements Fro...
So sánh Array và ArrayList trong Java
Introduction to Netflix Archaius with Spring Cloud
Spring Boot - Twilio
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Java Program to Implement Flood Fill Algorithm
Java Byte Array to InputStream
How to Get the Last Element of a Stream in Java?
Java – Write an InputStream to a File
JWT – Token-based Authentication trong Jersey 2.x
Một số ký tự đặc biệt trong Java
Java Program to Find the Median of two Sorted Arrays using Binary Search Approach
The Registration API becomes RESTful
Java Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected
Java Program to Implement Fermat Factorization Algorithm
Tìm hiểu về xác thực và phân quyền trong ứng dụng
Using Optional with Jackson
String Operations with Java Streams
Converting Iterator to List
Jackson – Change Name of Field
Java Program to Describe the Representation of Graph using Incidence Matrix
Java Program to Implement a Binary Search Algorithm for a Specific Search Sequence
Marker Interface trong Java
How to Use if/else Logic in Java 8 Streams