You are given input as order of graph n (highest number of edges connected to a node), you have to find the 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 an 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 the 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*

## Java

`// Java program to find vertices in ` `// a hypercube graph of order n ` `class` `GfG ` `{ ` ` ` ` ` `// Function to find power of 2 ` ` ` `static` `int` `power(` `int` `n) ` ` ` `{ ` ` ` `if` `(n == ` `1` `) ` ` ` `return` `2` `; ` ` ` `return` `2` `* power(n - ` `1` `); ` ` ` `} ` ` ` ` ` `// Driver program ` ` ` `public` `static` `void` `main(String []args) ` ` ` `{ ` ` ` ` ` `// n is the order of the graph ` ` ` `int` `n = ` `4` `; ` ` ` `System.out.println(power(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Rituraj Jain ` |

*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*

## C#

`// C# program to find vertices in ` `// a hypercube graph of order n ` `using` `System; ` ` ` `class` `GfG ` `{ ` ` ` ` ` `// Function to find power of 2 ` ` ` `static` `int` `power(` `int` `n) ` ` ` `{ ` ` ` `if` `(n == 1) ` ` ` `return` `2; ` ` ` `return` `2 * power(n - 1); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` ` ` `// n is the order of the graph ` ` ` `int` `n = 4; ` ` ` `Console.WriteLine(power(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Mukul Singh ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find vertices in ` `// a hypercube graph of order n ` `{ ` ` ` ` ` `// Function to find power of 2 ` ` ` `function` `power(` `$n` `) ` ` ` `{ ` ` ` `if` `(` `$n` `== 1) ` ` ` `return` `2; ` ` ` `return` `2 * power(` `$n` `- 1); ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `{ ` ` ` ` ` `// n is the order of the graph ` ` ` `$n` `= 4; ` ` ` `echo` `(power(` `$n` `)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Code_Mech ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

16

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Maximum number of edges that N-vertex graph can have such that graph is Triangle free | Mantel's Theorem
- Detect cycle in the graph using degrees of nodes of graph
- Graph implementation using STL for competitive programming | Set 2 (Weighted graph)
- Convert undirected connected graph to strongly connected directed graph
- Islands in a graph using BFS
- Sum of dependencies in a graph
- Transpose graph
- Dominant Set of a Graph
- BFS for Disconnected Graph
- Biconnected graph
- Bridges in a graph
- Graph and its representations
- Check for star graph
- A Peterson Graph Problem
- Implementation of Graph in JavaScript
- Degree of a Cycle Graph
- Minimum Cost Graph
- Count of different groups using Graph
- Graph representations using set and hash

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.