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:
Java Program to Implement Find all Back Edges in a Graph
So sánh HashMap và Hashtable trong Java
Spring 5 Functional Bean Registration
Spring Boot - Build Systems
Refactoring Design Pattern với tính năng mới trong Java 8
Java – InputStream to Reader
Java Program to Implement Adjacency List
Java Program to Implement Interpolation Search Algorithm
Java Program to Implement Queue using Two Stacks
Java Program to Implement ArrayList API
Java Program to Generate a Sequence of N Characters for a Given Specific Case
Simple Single Sign-On with Spring Security OAuth2
Reading an HTTP Response Body as a String in Java
Java Program to Implement Caesar Cypher
Java Program to Describe the Representation of Graph using Adjacency List
Lớp lồng nhau trong java (Java inner class)
Examine the internal DNS cache
Java Program to Perform Inorder Recursive Traversal of a Given Binary Tree
Tổng quan về ngôn ngữ lập trình java
More Jackson Annotations
Guide to CopyOnWriteArrayList
Java Program to Implement Sorted Circular Doubly Linked List
Java Program to find the maximum subarray sum O(n^2) time(naive method)
Interface trong Java 8 – Default method và Static method
Quick Guide to Spring Controllers
REST Web service: Tạo ứng dụng Java RESTful Client với Jersey Client 2.x
Java Program to Implement Min Hash
Java – Create a File
Spring Web Annotations
Java InputStream to Byte Array and ByteBuffer
Java Program to Find the Connected Components of an UnDirected Graph
Tránh lỗi NullPointerException trong Java như thế nào?