Total number of Spanning trees in a Cycle Graph
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 the 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 trees will always be equal to the number of vertices in a cycle graph.
Implementation:
C++
#include <bits/stdc++.h>
using namespace std;
int Spanning( int vertices)
{
int result = 0;
result = vertices;
return result;
}
int main()
{
int vertices = 4;
cout << "Spanning tree = " << Spanning(vertices);
return 0;
}
|
Java
import java.io.*;
class GFG {
static int Spanning( int vertices)
{
int result = 0 ;
result = vertices;
return result;
}
public static void main (String[] args) {
int vertices = 4 ;
System.out.println( "Spanning tree = " + Spanning(vertices));
}
}
|
Python3
def Spanning( vertices):
result = 0
result = vertices
return result
vertices = 4
print ( "Spanning tree = " ,
Spanning(vertices))
|
C#
using System;
class GFG
{
public int Spanning( int vertices)
{
int result = 0;
result = vertices;
return result;
}
public static void Main()
{
GFG g = new GFG();
int vertices = 4;
Console.WriteLine( "Spanning tree = {0}" ,
g.Spanning(vertices));
}
}
|
PHP
<?php
function Spanning( $vertices )
{
$result = 0;
$result = $vertices ;
return $result ;
}
$vertices = 4;
echo "Spanning tree = " .
Spanning( $vertices );
?>
|
Javascript
<script>
function Spanning(vertices)
{
result = 0;
result = vertices;
return result;
}
var vertices = 4;
document.write( "Spanning tree = " +
Spanning(vertices));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
23 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...