Total number of Spanning trees in a Cycle Graph

14 Apr, 2021
Given the number of vertices in a Cycle graph. The task is to find the Total number of Spanning trees possible. Note: A cycle/circular graph is a graph that contains only one cycle. A spanning tree is a shortest/minimum path in a graph that covers all the vertices of a graph.
Examples:  
Input: Vertices = 3
Output: Total Spanning tree = 3

Input: Vertices = 4
Output: Total Spanning tree = 4
Example 1: For Cycle Graph with vertices = 3  
Spanning Tree possible is 3  
Example 2: For Cycle Graph with vertices = 4  
Spanning Tree possible is 4  
So, the number of spanning treess will always be equal to the number of vertices in a cycle graph.
Below is the required implementation: 
C++
Java
Python3
C#
PHP
Javascript
// C++ program to find number of// spanning trees#include <bits/stdc++.h>using namespace std; // function that calculates the// total Spanning treeint Spanning(int vertices){    result = 0;     result = vertices;    return result;} // Driver codeint main(){    int vertices = 4;     cout << "Spanning tree = " << Spanning(vertices);    return 0;}
// Java program to find number of// spanning trees import java.io.*; class GFG { // function that calculates the// total Spanning treestatic int Spanning(int vertices){    int result = 0;     result = vertices;    return result;} // Driver code    public static void main (String[] args) {    int vertices = 4;     System.out.println("Spanning tree = " + Spanning(vertices));    }}// This code is contributed // by chandan_jnu..
# Python program to find number of# spanning trees # function that calculates the# total Spanning treedef Spanning( vertices):        result = 0     result = vertices    return result # Driver codevertices = 4print("Spanning tree = ",       Spanning(vertices)) # This code is contributed# by Sanjit_Prasad
// C# program to find number// of spanning treesusing System; // function that calculates// the total Spanning treeclass GFG{public int Spanning(int vertices){    int result = 0;     result = vertices;    return result;} // Driver codepublic static void Main(){    GFG g = new GFG();    int vertices = 4;     Console.WriteLine("Spanning tree = {0}",                        g.Spanning(vertices));}} // This code is contributed// by Soumik
<?php// PHP program to find number of// spanning trees // function that calculates the// total Spanning treefunction Spanning($vertices){    $result = 0;     $result = $vertices;    return $result;} // Driver code$vertices = 4; echo "Spanning tree = " .     Spanning($vertices);      // This code is contributed// by Ankita Saini?>
<script> // Javascript program to find number of// spanning trees // Function that calculates the// total Spanning treefunction Spanning(vertices){    result = 0;    result = vertices;    return result;} // Driver codevar vertices = 4;document.write("Spanning tree = " +               Spanning(vertices)); // This code is contributed by noob2000 </script>
Spanning tree = 4
 
Chandan_Kumar
SoumikMondal
Sanjit_Prasad
ankita_saini
noob2000
Algorithms-Graph Minimum Spanning Tree
graph-cycle
Graph
School Programming
Graph
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Find if there is a path between two vertices in a directed graph
Introduction to Data Structures
Find if there is a path between two vertices in an undirected graph
What is Data Structure: Types, Classifications and Applications
Top 50 Graph Coding Problems for Interviews
Python Dictionary
Reverse a string in Java
Arrays in C/C++
Introduction To PYTHON
Interfaces in Java