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:
Jackson – JsonMappingException (No serializer found for class)
Guide to the Synchronized Keyword in Java
Java Timer
Chuyển đổi từ HashMap sang ArrayList
JPA/Hibernate Persistence Context
Spring 5 Testing with @EnabledIf Annotation
Connect through a Proxy
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Java Program to Describe the Representation of Graph using Incidence List
How to Return 404 with Spring WebFlux
Spring Boot - Exception Handling
Spring Cloud AWS – EC2
Xây dựng ứng dụng Client-Server với Socket trong Java
Java Program to Perform the Unique Factorization of a Given Number
An Introduction to ThreadLocal in Java
Java Program to Perform Finite State Automaton based Search
Java Optional as Return Type
Hướng dẫn Java Design Pattern – Template Method
Mảng (Array) trong Java
Giới thiệu luồng vào ra (I/O) trong Java
Java Program to Implement Sorted Circularly Singly Linked List
Guide to DelayQueue
Java Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree
Java Program to Check if it is a Sparse Matrix
Java Program to Implement ArrayBlockingQueue API
Converting Iterator to List
Get and Post Lists of Objects with RestTemplate
Spring Data JPA @Query
Spring – Injecting Collections
Spring Boot - Cloud Configuration Client
Hướng dẫn sử dụng Java Reflection
Java – Write an InputStream to a File