# 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 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++

`// C++ program to find number of ` `// spanning trees ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function that calculates the ` `// total Spanning tree ` `int` `Spanning(` `int` `vertices) ` `{ ` ` ` `result = 0; ` ` ` ` ` `result = vertices; ` ` ` `return` `result; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `vertices = 4; ` ` ` ` ` `cout << ` `"Spanning tree = "` `<< Spanning(vertices); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find number of ` `// spanning trees ` ` ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` `// function that calculates the ` `// total Spanning tree ` `static` `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.. ` |

*chevron_right*

*filter_none*

## Python3

`# Python program to find number of ` `# spanning trees ` ` ` `# function that calculates the ` `# total Spanning tree ` `def` `Spanning( vertices): ` ` ` `result ` `=` `0` ` ` ` ` `result ` `=` `vertices ` ` ` `return` `result ` ` ` `# Driver code ` `vertices ` `=` `4` `print` `(` `"Spanning tree = "` `, ` ` ` `Spanning(vertices)) ` ` ` `# This code is contributed ` `# by Sanjit_Prasad ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find number ` `// of spanning trees ` `using` `System; ` ` ` `// function that calculates ` `// the total Spanning tree ` `class` `GFG ` `{ ` `public` `int` `Spanning(` `int` `vertices) ` `{ ` ` ` `int` `result = 0; ` ` ` ` ` `result = vertices; ` ` ` `return` `result; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `GFG g = ` `new` `GFG(); ` ` ` `int` `vertices = 4; ` ` ` ` ` `Console.WriteLine(` `"Spanning tree = {0}"` `, ` ` ` `g.Spanning(vertices)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Soumik ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find number of ` `// spanning trees ` ` ` `// function that calculates the ` `// total Spanning tree ` `function` `Spanning(` `$vertices` `) ` `{ ` ` ` `$result` `= 0; ` ` ` ` ` `$result` `= ` `$vertices` `; ` ` ` `return` `$result` `; ` `} ` ` ` `// Driver code ` `$vertices` `= 4; ` ` ` `echo` `"Spanning tree = "` `. ` ` ` `Spanning(` `$vertices` `); ` ` ` `// This code is contributed ` `// by Ankita Saini ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Spanning tree = 4

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Total number of Spanning Trees in a Graph
- Number of single cycle components in an undirected graph
- Detect cycle in the graph using degrees of nodes of graph
- Program to find total number of edges in a Complete Graph
- Algorithms | Graph Minimum Spanning Tree | Question 4
- Algorithms | Graph Minimum Spanning Tree | Question 7
- Algorithms | Graph Minimum Spanning Tree | Question 6
- Algorithms | Graph Minimum Spanning Tree | Question 5
- Algorithms | Graph Minimum Spanning Tree | Question 8
- Algorithms | Graph Minimum Spanning Tree | Question 3
- Algorithms | Graph Minimum Spanning Tree | Question 2
- Algorithms | Graph Minimum Spanning Tree | Question 1
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Degree of a Cycle Graph
- Coloring a Cycle Graph
- Detect cycle in an undirected graph using BFS
- Count of all cycles without any inner cycle in a given Graph
- Detect Cycle in a Directed Graph
- Detect cycle in an undirected graph
- Detect Cycle in a Directed Graph using BFS

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.