Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph

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 Ternary Search Algorithm
Java Program to Implement Hash Tables with Double Hashing
Database Migrations with Flyway
How to Get All Spring-Managed Beans?
Merging Two Maps with Java 8
Java Program to Check if a Given Graph Contain Hamiltonian Cycle or Not
Java Program to Implement Cubic convergence 1/pi Algorithm
Batch Processing with Spring Cloud Data Flow
Setting a Request Timeout for a Spring REST API
Registration with Spring Security – Password Encoding
Spring Boot - Logging
Java InputStream to String
Assert an Exception is Thrown in JUnit 4 and 5
Spring Boot - Service Components
Instance Profile Credentials using Spring Cloud
Java Program to Implement Karatsuba Multiplication Algorithm
Hướng dẫn Java Design Pattern – Dependency Injection
Java Program to Check Whether a Given Point is in a Given Polygon
Deque và ArrayDeque trong Java
@DynamicUpdate with Spring Data JPA
Giới thiệu thư viện Apache Commons Chain
A Guide to Concurrent Queues in Java
Spring Boot Tutorial – Bootstrap a Simple Application
Jackson Ignore Properties on Marshalling
Java Program to Find kth Smallest Element by the Method of Partitioning the Array
Java Program to Perform Complex Number Multiplication
Working with Tree Model Nodes in Jackson
Java Program to Perform Preorder Recursive Traversal of a Given Binary Tree
Java Web Services – Jersey JAX-RS – REST và sử dụng REST API testing tools với Postman
Difference Between Wait and Sleep in Java
Java Program to Implement Threaded Binary Tree
Lớp HashMap trong Java