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:
Apache Camel with Spring Boot
Java Program to Implement Karatsuba Multiplication Algorithm
Java – Reader to Byte Array
Setting the Java Version in Maven
String Operations with Java Streams
Spring 5 Testing with @EnabledIf Annotation
An Intro to Spring Cloud Contract
Spring Data MongoDB – Indexes, Annotations and Converters
A Guide to Iterator in Java
Java Program to Implement Double Ended Queue
Java Program to Implement Fenwick Tree
Java Program to Check whether Directed Graph is Connected using DFS
Java Program to Implement Sieve Of Sundaram
ArrayList trong java
Java Program to Implement Aho-Corasick Algorithm for String Matching
Java Program to Find Nearest Neighbor Using Linear Search
Custom Thread Pools In Java 8 Parallel Streams
Overflow and Underflow in Java
Giới thiệu Google Guice – Injection, Scope
Simultaneous Spring WebClient Calls
Java Program for Douglas-Peucker Algorithm Implementation
Immutable Objects in Java
Java Program to Describe the Representation of Graph using Adjacency List
Java List UnsupportedOperationException
Java Perform to a 2D FFT Inplace Given a Complex 2D Array
Immutable ArrayList in Java
Hướng dẫn Java Design Pattern – Object Pool
Java Program to Implement Gift Wrapping Algorithm in Two Dimensions
Java Program to Implement Branch and Bound Method to Perform a Combinatorial Search
Java Program to Implement Word Wrap Problem
Hướng dẫn tạo và sử dụng ThreadPool trong Java
Hướng dẫn Java Design Pattern – Command