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:
Migrating from JUnit 4 to JUnit 5
Tạo chương trình Java đầu tiên sử dụng Eclipse
Java Program to Check for balanced parenthesis by using Stacks
Giới thiệu Google Guice – Dependency injection (DI) framework
Java Switch Statement
Servlet 3 Async Support with Spring MVC and Spring Security
Java TreeMap vs HashMap
Apache Tiles Integration with Spring MVC
Receive email using IMAP
Introduction to Spring Cloud OpenFeign
Java Program to Check Multiplicability of Two Matrices
Spring Boot Configuration with Jasypt
Posting with HttpClient
Guide to java.util.concurrent.Future
Bootstrapping Hibernate 5 with Spring
Test a REST API with Java
A Quick Guide to Spring Cloud Consul
Java Program to Generate Random Partition out of a Given Set of Numbers or Characters
Java Program to Implement Sorted Circular Doubly Linked List
Reading an HTTP Response Body as a String in Java
Lập trình đa luồng với CompletableFuture trong Java 8
Java Program to Find the Connected Components of an UnDirected Graph
Java Program to Find Nearest Neighbor for Dynamic Data Set
Từ khóa throw và throws trong Java
Apache Commons Collections OrderedMap
Spring Boot - Tomcat Deployment
Spring Webflux with Kotlin
Java Program to Print only Odd Numbered Levels of a Tree
A Guide to JPA with Spring
Java Program to Implement Disjoint Sets
Mockito and JUnit 5 – Using ExtendWith
Remove the First Element from a List