📜  超立方体图

📅  最后修改于: 2022-05-13 01:57:54.028000             🧑  作者: Mango

超立方体图

您以图 n 的顺序给出输入(连接到节点的最大边数),您必须找到 n 阶超立方体图中的顶点数。

例子:

Input : n = 3
Output : 8

Input : n = 2
Output : 4

在超立方体图 Q(n) 中,n 表示图的度数。超立方体图表示可以连接到图以使其成为n度图的最大边数,每个顶点具有相同的度n,并且在该表示中,仅添加固定数量的边和顶点,如图所示以下:

超立方体图

所有的超立方图都是哈密顿图,n阶的超立方图有(2^n)个顶点,对于输入n作为图的阶,我们必须找到2的对应幂。

C++
// C++ program to find vertices in a hypercube 
// graph of order n
#include 
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;
}


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


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


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


PHP


Javascript


输出:

16