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:
Lập trình đa luồng với CompletableFuture trong Java 8
Java Program to Implement Disjoint Set Data Structure
Spring Boot with Multiple SQL Import Files
Runnable vs. Callable in Java
Custom JUnit 4 Test Runners
Introduction to Spring Data JPA
Java Program to Find kth Smallest Element by the Method of Partitioning the Array
Introduction to Spring Method Security
Java Program to Perform Polygon Containment Test
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Spring Data Reactive Repositories with MongoDB
Using Custom Banners in Spring Boot
@Order in Spring
Java Program to Check Multiplicability of Two Matrices
Hướng dẫn Java Design Pattern – Abstract Factory
Optional trong Java 8
Java Program to Implement Pairing Heap
Java Program to Implement Stack using Linked List
Java Program to Find the Nearest Neighbor Using K-D Tree Search
Guide to Java OutputStream
Inheritance and Composition (Is-a vs Has-a relationship) in Java
Hướng dẫn Java Design Pattern – Template Method
Các chương trình minh họa sử dụng Cấu trúc điều khiển trong Java
Java Program to Implement an Algorithm to Find the Global min Cut in a Graph
Guide to the Synchronized Keyword in Java
Java Program to Implement Sorted Singly Linked List
Java Program to Check if it is a Sparse Matrix
Convert Hex to ASCII in Java
Feign – Tạo ứng dụng Java RESTful Client
Jackson JSON Views
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 Check whether Graph is a Bipartite using BFS