You are given input as order of graph n (highest number of edges connected to a node), you have to find number of vertices in a Hypercube graph of order n.

Examples:

Input : n = 3 Output : 8 Input : n = 2 Output : 4

In hypercube graph Q(n), n represents the degree of the graph. Hypercube graph represents the maximum number of edges that can be connected to a graph to make it a n degree graph, every vertex has same degree n and in that representation only a fixed number of edges and vertices are added as shown in the figure below:

All hypercube graphs are Hamiltonian, **hypercube graph of order n has (2^n) vertices, **, for input n as order of graph we have to find the corresponding power of 2.

## C++

`// C++ program to find vertices in a hypercube ` `// graph of order n ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// function to find power of 2 ` `int` `power(` `int` `n) ` `{ ` ` ` `if` `(n == 1) ` ` ` `return` `2; ` ` ` `return` `2 * power(n - 1); ` `} ` ` ` `// driver program ` `int` `main() ` `{ ` ` ` `// n is the order of the graph ` ` ` `int` `n = 4; ` ` ` `cout << power(n); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find vertices in a hypercube ` `# graph of order n ` ` ` `# function to find power of 2 ` `def` `power(n): ` ` ` `if` `n` `=` `=` `1` `: ` ` ` `return` `2` ` ` `return` `2` `*` `power(n` `-` `1` `) ` ` ` ` ` `# Dricer code ` `n ` `=` `4` `print` `(power(n)) ` ` ` ` ` `# This code is contributed by Shrikant13 ` |

*chevron_right*

*filter_none*

**Output:**

16

## Recommended Posts:

- Breadth First Search or BFS for a Graph
- Find if there is a path between two vertices in a directed graph
- Depth First Search or DFS for a Graph
- Detect Cycle in a Directed Graph
- Disjoint Set (Or Union-Find) | Set 1 (Detect Cycle in an Undirected Graph)
- Graph and its representations
- Transitive closure of a graph
- Check whether a given graph is Bipartite or not
- Shortest Path in Directed Acyclic Graph
- Bridges in a graph
- Articulation Points (or Cut Vertices) in a Graph
- Biconnected graph
- Check if a graph is strongly connected | Set 1 (Kosaraju using DFS)
- Eulerian path and circuit for undirected graph
- Longest Path in a Directed Acyclic Graph

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.