- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# Program to find the diameter, cycles and edges of a Wheel Graph in C++

In this problem, we are given a number that denotes the number of vertices of a Wheel Graph. Our task is to create a *Program to find the diameter,
cycles and edges of a Wheel Graph in C++*.

**Problem description** − Here, we need to find the number of cycles, number of edges, and the diameter of Wheel Graph with n vertices.

First, let’s understand some basics about Wheel Graph −

A wheel graph is obtained from a cycle graph Cn-1 by adding a new vertex. That new vertex is called a Hub which is connected to all the vertices of Cn.

Example of a wheel graph with 7 vertices.

**Diameter of wheel Graph** is the number of edges that we need to cover to go from anyone vertices to others. For the above Wheel Graph, the **diameter
is 2**

**No. of Cycle of Wheel Graph** is the total number of closed cycles that can be the given graph. For the above Wheel Graph, the no. of cycles is 31.

**No. of Edge of Wheel Graph** is the count of edges that connect all the vertices. For the above Wheel Graph, no of edges is 12.

## Solution Approach

To solve the problem, we will be using the direct formula that is given in the graph theory to find the required values for a wheel graph.

The Formulas are,

**Diameter of a Wheel Graph =**

1, if vertices = 4, else 2.

**No. of cycles of a Wheel Graph =**

(No. of vertices )^2 - (3 * (No. of vertices -1) )

**No. of edges of a wheel Graph =**

2 * (No. of vertices - 1)

**Program to illustrate the working of our solution,**

## Example

#include <iostream> #include <math.h> using namespace std; void calcValuesWheelGraph(int V){ // Calculating the Diameter if(V == 4){ cout<<"The Diameter of the Wheel Graph is 1 "<<endl; } else { cout<<"The Diameter of the Wheel Graph is 2 "<<endl; } // Calculating the no. of cycles cout<<"The number of cycles of the Wheel Graph is "<<(pow(V, 2) - (3 * (V-1)))<<endl; // Calculating the no. of Edges cout<<"The number of Edges of the Wheel Graph is "<<(2 * (V-1))<<endl; } int main(){ int V = 9; calcValuesWheelGraph(V); return 0; }

## Output

The Diameter of the Wheel Graph is 2 The number of cycles of the Wheel Graph is 57 The number of Edges of the Wheel Graph is 16

- Related Articles
- C++ Program to Find All Forward Edges in a Graph
- Program to find out the critical and pseudo-critical edges in a graph in Python
- C++ Program to find out the number of bridge edges in a given graph
- Program to Find Out the Edges that Disconnect the Graph in Python
- A bicycle wheel makes $5, 000$ revolutions in moving $11\ km$. Find the circumference and the diameter of the wheel.
- Edges and Vertices of Graph
- C++ Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected\n
- C++ Program to Generate a Random UnDirected Graph for a Given Number of Edges
- Print all the cycles in an undirected graph in C++
- C++ Program to Generate a Random Directed Acyclic Graph DAC for a Given Number of Edges
- Product of lengths of all cycles in an undirected graph in C++
- Maximum number of edges in Bipartite graph in C++
- If $\pi=\frac{22}{7}$, then find the distance covered in a revolution $( in\ m)$ of a wheel of diameter $35\ cm$.
- Count number of edges in an undirected graph in C++
- If $\pi=\frac{22}{7}$, then find the distance covered in the revolution $( in\ m)$ of a wheel of diameter $35\ cm$.