---
title: "HypercubeGraph"
language: "en"
type: "Symbol"
summary: "HypercubeGraph[n] gives the n-dimensional hypercube graph Qn."
keywords: 
- hypercube
- n-cube graph
- n-hypercube graph
canonical_url: "https://reference.wolfram.com/language/ref/HypercubeGraph.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Graph Construction & Representation"
    link: "https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md"
related_functions: 
  - 
    title: "Graph"
    link: "https://reference.wolfram.com/language/ref/Graph.en.md"
  - 
    title: "GraphData"
    link: "https://reference.wolfram.com/language/ref/GraphData.en.md"
  - 
    title: "CompleteGraph"
    link: "https://reference.wolfram.com/language/ref/CompleteGraph.en.md"
---
# HypercubeGraph

HypercubeGraph[n] gives the n-dimensional hypercube graph $Q_n$.

## Details and Options

* ``HypercubeGraph[n]`` is a graph with $2^n$ vertices that is the product of ``n`` copies of the complete graph $K_2$.

[image]

* ``HypercubeGraph`` takes the same options as ``Graph``.

### List of all options

|                        |                 |                                                                                    |
| ---------------------- | --------------- | ---------------------------------------------------------------------------------- |
| AlignmentPoint         | Center          | the default point in the graphic to align with                                     |
| AnnotationRules        | {}              | annotations for graph, edges and vertices                                          |
| AspectRatio            | Automatic       | ratio of height to width                                                           |
| Axes                   | False           | whether to draw axes                                                               |
| AxesLabel              | None            | axes labels                                                                        |
| AxesOrigin             | Automatic       | where axes should cross                                                            |
| AxesStyle              | {}              | style specifications for the axes                                                  |
| Background             | None            | background color for the plot                                                      |
| BaselinePosition       | Automatic       | how to align with a surrounding text baseline                                      |
| BaseStyle              | {}              | base style specifications for the graphic                                          |
| ContentSelectable      | Automatic       | whether to allow contents to be selected                                           |
| CoordinatesToolOptions | Automatic       | detailed behavior of the coordinates tool                                          |
| DirectedEdges          | Automatic       | whether to interpret Rule as DirectedEdge                                          |
| EdgeLabels             | None            | labels and label placements for edges                                              |
| EdgeLabelStyle         | Automatic       | style to use for edge labels                                                       |
| EdgeShapeFunction      | Automatic       | generate graphic shapes for edges                                                  |
| EdgeStyle              | Automatic       | style used for edges                                                               |
| EdgeWeight             | Automatic       | weights for edges                                                                  |
| Epilog                 | {}              | primitives rendered after the main plot                                            |
| FormatType             | TraditionalForm | the default format type for text                                                   |
| Frame                  | False           | whether to put a frame around the plot                                             |
| FrameLabel             | None            | frame labels                                                                       |
| FrameStyle             | {}              | style specifications for the frame                                                 |
| FrameTicks             | Automatic       | frame ticks                                                                        |
| FrameTicksStyle        | {}              | style specifications for frame ticks                                               |
| GraphHighlight         | {}              | graph elements to highlight                                                        |
| GraphHighlightStyle    | Automatic       | style for highlight                                                                |
| GraphLayout            | Automatic       | how to lay out vertices and edges                                                  |
| GridLines              | None            | grid lines to draw                                                                 |
| GridLinesStyle         | {}              | style specifications for grid lines                                                |
| ImageMargins           | 0.              | the margins to leave around the graphic                                            |
| ImagePadding           | All             | what extra padding to allow for labels etc.                                        |
| ImageSize              | Automatic       | the absolute size at which to render the graphic                                   |
| LabelStyle             | {}              | style specifications for labels                                                    |
| Method                 | Automatic       | details of graphics methods to use                                                 |
| PerformanceGoal        | Automatic       | aspects of performance to try to optimize                                          |
| PlotLabel              | None            | an overall label for the plot                                                      |
| PlotRange              | All             | range of values to include                                                         |
| PlotRangeClipping      | False           | whether to clip at the plot range                                                  |
| PlotRangePadding       | Automatic       | how much to pad the range of values                                                |
| PlotRegion             | Automatic       | the final display region to be filled                                              |
| PlotTheme              | \$PlotTheme     | overall theme for the graph                                                        |
| PreserveImageOptions   | Automatic       | whether to preserve image options when displaying new versions of the same graphic |
| Prolog                 | {}              | primitives rendered before the main plot                                           |
| RotateLabel            | True            | whether to rotate y labels on the frame                                            |
| Ticks                  | Automatic       | axes ticks                                                                         |
| TicksStyle             | {}              | style specifications for axes ticks                                                |
| VertexCoordinates      | Automatic       | coordinates for vertices                                                           |
| VertexLabels           | None            | labels and placements for vertices                                                 |
| VertexLabelStyle       | Automatic       | style to use for vertex labels                                                     |
| VertexShape            | Automatic       | graphic shape for vertices                                                         |
| VertexShapeFunction    | Automatic       | generate graphic shapes for vertices                                               |
| VertexSize             | Medium          | size of vertices                                                                   |
| VertexStyle            | Automatic       | styles for vertices                                                                |
| VertexWeight           | Automatic       | weights for vertices                                                               |

---

## Examples (95)

### Basic Examples (1)

The first few hypercubes:

```wl
In[1]:= Table[HypercubeGraph[i, PlotLabel -> Subscript[Q, i]], {i, 2, 4}]

Out[1]= {[image], [image], [image]}
```

### Options (79)

#### AnnotationRules (2)

Specify an annotation for vertices:

```wl
In[1]:= HypercubeGraph[3, AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]

Out[1]= [image]
```

---

Edges:

```wl
In[1]:= HypercubeGraph[3, AnnotationRules -> {1\[UndirectedEdge]2 -> {EdgeLabels -> "hello"}}]

Out[1]= [image]
```

#### EdgeLabels (7)

Label the edge ``1\[UndirectedEdge]2`` :

```wl
In[1]:= HypercubeGraph[3, EdgeLabels -> {1\[UndirectedEdge]2 -> "Hello"}]

Out[1]= [image]
```

---

Label all edges individually:

```wl
In[1]:= el = EdgeList[HypercubeGraph[3]]

Out[1]= {1\[UndirectedEdge]2, 1\[UndirectedEdge]3, 1\[UndirectedEdge]5, 2\[UndirectedEdge]4, 2\[UndirectedEdge]6, 3\[UndirectedEdge]4, 3\[UndirectedEdge]7, 4\[UndirectedEdge]8, 5\[UndirectedEdge]6, 5\[UndirectedEdge]7, 6\[UndirectedEdge]8, 7\[UndirectedEdge]8}

In[2]:= HypercubeGraph[3, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]

Out[2]= [image]
```

---

Use any expression as a label:

```wl
In[1]:= HypercubeGraph[3, EdgeLabels -> {2\[UndirectedEdge]4 -> [image], 3\[UndirectedEdge]4 -> [image], 1\[UndirectedEdge]3 -> [image]}]

Out[1]= [image]
```

---

Use ``Placed`` with symbolic locations to control label placement along an edge:

```wl
In[1]:= Table[HypercubeGraph[2, EdgeLabels -> {1\[UndirectedEdge]3 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]

Out[1]= {[image], [image], [image]}
```

---

Use explicit coordinates to place labels:

```wl
In[1]:= Table[HypercubeGraph[2, EdgeLabels -> {1\[UndirectedEdge]3 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]

Out[1]= {[image], [image], [image]}
```

Vary positions within the label:

```wl
In[2]:= Table[HypercubeGraph[2, EdgeLabels -> {1\[UndirectedEdge]3 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[2]= {[image], [image], [image]}
```

---

Place multiple labels:

```wl
In[1]:= HypercubeGraph[3, EdgeLabels -> {3\[UndirectedEdge]1 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]

Out[1]= [image]

In[2]:= HypercubeGraph[3, EdgeLabels -> {3\[UndirectedEdge]1 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]

Out[2]= [image]
```

---

Use automatic labeling by values through ``Tooltip`` and ``StatusArea`` :

```wl
In[1]:= HypercubeGraph[3, EdgeLabels -> Placed["Name", Tooltip]]

Out[1]= [image]

In[2]:= HypercubeGraph[3, EdgeLabels -> Placed["Name", StatusArea]]

Out[2]= [image]
```

#### EdgeShapeFunction (6)

Get a list of built-in settings for ``EdgeShapeFunction`` :

```wl
In[1]:= ResourceData["EdgeShapeFunction"]

Out[1]= {"Arrow", "BoxLine", "CarvedArcArrow", "CarvedArrow", "DashedLine", "DiamondLine", "DotLine", "DottedLine", "FilledArcArrow", "FilledArrow", "HalfFilledArrow", "HalfFilledDoubleArrow", "HalfUnfilledArrow", "HalfUnfilledDoubleArrow", "Line", "ShortCarvedArcArrow", "ShortCarvedArrow", "ShortFilledArcArrow", "ShortFilledArrow", "ShortUnfilledArcArrow", "ShortUnfilledArrow", "UnfilledArcArrow", "UnfilledArrow"}
```

---

Undirected edges including the basic line:

```wl
In[1]:= HypercubeGraph[2, EdgeShapeFunction -> "Line"]

Out[1]= [image]
```

Lines with different glyphs on the edges:

```wl
In[2]:= Table[HypercubeGraph[2, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]

Out[2]= {[image], [image], [image]}
```

---

Directed edges including solid arrows:

```wl
In[1]:= Table[HypercubeGraph[2, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]

Out[1]= {[image], [image], [image], [image], [image], [image]}
```

Line arrows:

```wl
In[2]:= Table[HypercubeGraph[2, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]

Out[2]= {[image], [image], [image], [image], [image], [image]}
```

Open arrows:

```wl
In[3]:= Table[HypercubeGraph[2, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]

Out[3]= {[image], [image], [image], [image]}
```

---

Specify an edge function for an individual edge:

```wl
In[1]:= HypercubeGraph[2, EdgeShapeFunction -> {1\[UndirectedEdge]2 -> "DotLine"}]

Out[1]= [image]
```

Combine with a different default edge function:

```wl
In[2]:= HypercubeGraph[2, EdgeShapeFunction -> {1\[UndirectedEdge]2 -> "BoxLine", "DotLine"}]

Out[2]= [image]
```

---

Draw edges by running a program:

```wl
In[1]:=
ef[pts_List, e_] := 
	Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]

In[2]:= HypercubeGraph[2, EdgeShapeFunction -> ef]

Out[2]= [image]
```

---

``EdgeShapeFunction`` can be combined with ``EdgeStyle`` :

```wl
In[1]:= HypercubeGraph[2, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]

Out[1]= [image]
```

``EdgeShapeFunction`` has higher priority than ``EdgeStyle`` :

```wl
In[2]:= HypercubeGraph[2, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]

Out[2]= [image]
```

#### EdgeStyle (2)

Style all edges:

```wl
In[1]:= Table[HypercubeGraph[3, EdgeStyle -> style, PlotLabel -> style], {style, {Gray, Dashed, Thick}}]

Out[1]= {[image], [image], [image]}
```

---

Style individual edges:

```wl
In[1]:= HypercubeGraph[3, EdgeStyle -> {1\[UndirectedEdge]2 -> Blue, 1\[UndirectedEdge]3 -> Dashed}]

Out[1]= [image]
```

#### EdgeWeight (2)

Specify a weight for all edges:

```wl
In[1]:= HypercubeGraph[2, EdgeWeight -> RandomInteger[5, 4]]

Out[1]= [image]

In[2]:= WeightedAdjacencyMatrix[%]//MatrixForm

Out[2]//MatrixForm=
(⁠|   |   |   |   |
| - | - | - | - |
| 0 | 5 | 4 | 0 |
| 5 | 0 | 0 | 5 |
| 4 | 0 | 0 | 5 |
| 0 | 5 | 5 | 0 |⁠)
```

---

Use any numeric expression as a weight:

```wl
In[1]:= HypercubeGraph[2, EdgeWeight -> {a, b, c, d}]

Out[1]= [image]

In[2]:= WeightedAdjacencyMatrix[%]//MatrixForm

Out[2]//MatrixForm=
(⁠|   |   |   |   |
| - | - | - | - |
| 0 | a | b | 0 |
| a | 0 | 0 | c |
| b | 0 | 0 | d |
| 0 | c | d | 0 |⁠)
```

#### GraphHighlight (3)

Highlight the vertex ``1`` :

```wl
In[1]:= HypercubeGraph[3, VertexSize -> Medium, GraphHighlight -> {1}]

Out[1]= [image]
```

---

Highlight the edge ``1\[UndirectedEdge]3`` :

```wl
In[1]:= HypercubeGraph[3, VertexSize -> Tiny, GraphHighlight -> {1\[UndirectedEdge]3}]

Out[1]= [image]
```

---

Highlight vertices and edges:

```wl
In[1]:= HypercubeGraph[3, VertexSize -> Tiny, GraphHighlight -> {1, 2, 1\[UndirectedEdge]3, 1\[UndirectedEdge]5}]

Out[1]= [image]
```

#### GraphHighlightStyle (2)

Get a list of built-in settings for ``GraphHighlightStyle``:

```wl
In[1]:= ResourceData["GraphHighlightStyle"]

Out[1]= {Automatic, "Dashed", "Dotted", "Thick", "VertexConcaveDiamond", "VertexDiamond", "VertexTriangle", "DehighlightFade", "DehighlightGray", "DehighlightHide"}
```

---

Use built-in settings for ``GraphHighlightStyle`` :

```wl
In[1]:= HypercubeGraph[3, GraphHighlight -> {1, 1\[UndirectedEdge]3}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]

Out[1]= {[image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

#### GraphLayout (5)

By default, the layout is chosen automatically:

```wl
In[1]:= HypercubeGraph[3, GraphLayout -> Automatic]

Out[1]= [image]
```

---

Specify layouts on special curves:

```wl
In[1]:= Table[HypercubeGraph[5, GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]

Out[1]= {[image], [image]}
```

---

Specify layouts that satisfy optimality criteria:

```wl
In[1]:= Table[HypercubeGraph[5, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]

Out[1]= {[image], [image], [image]}
```

---

``VertexCoordinates`` overrides ``GraphLayout`` coordinates:

```wl
In[1]:=
{HypercubeGraph[3, GraphLayout -> "SpringElectricalEmbedding"], 
	HypercubeGraph[3, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 7}]]}

Out[1]= {[image], [image]}
```

---

Use ``AbsoluteOptions`` to extract ``VertexCoordinates`` computed using a layout algorithm:

```wl
In[1]:= HypercubeGraph[3]

Out[1]= [image]

In[2]:= AbsoluteOptions[%, VertexCoordinates]

Out[2]= {VertexCoordinates -> {{0.641132, 1.62564}, {1.54318, 1.62585}, {1.36415, 0.812419}, {2.18642, 0.814439}, {0., 0.811652}, {0.820712, 0.813688}, {0.643124, 0.}, {1.54492, 0.000533842}}}
```

#### PlotTheme (4)

##### Base Themes (2)

---

Use a common base theme:

```wl
In[1]:= HypercubeGraph[3, PlotTheme -> "Business"]

Out[1]= [image]
```

---

Use a monochrome theme:

```wl
In[1]:= HypercubeGraph[3, PlotTheme -> "Monochrome"]

Out[1]= [image]
```

##### Feature Themes (2)

---

Use a large graph theme:

```wl
In[1]:= HypercubeGraph[3, PlotTheme -> "LargeGraph"]

Out[1]= [image]
```

---

Use a classic diagram theme:

```wl
In[1]:= HypercubeGraph[3, PlotTheme -> "ClassicDiagram"]

Out[1]= [image]
```

#### VertexCoordinates (3)

By default, any vertex coordinates are computed automatically:

```wl
In[1]:= HypercubeGraph[3]

Out[1]= [image]
```

Extract the resulting vertex coordinates using ``AbsoluteOptions``:

```wl
In[2]:= AbsoluteOptions[%, VertexCoordinates]

Out[2]= {VertexCoordinates -> {{0.641132, 1.62564}, {1.54318, 1.62585}, {1.36415, 0.812419}, {2.18642, 0.814439}, {0., 0.811652}, {0.820712, 0.813688}, {0.643124, 0.}, {1.54492, 0.000533842}}}
```

---

Specify a layout function along an ellipse:

```wl
In[1]:= ellipseLayout[n_, {a_, b_}] := Table[{a Cos[2Pi / n u], b Sin[2Pi / n u]}, {u, 1, n}]

In[2]:= Graphics[Point[ellipseLayout[20, {2, 1}]]]

Out[2]= [image]
```

Use it to generate vertex coordinates for a graph:

```wl
In[3]:= HypercubeGraph[4, VertexCoordinates -> ellipseLayout[16, {2, 1}]]

Out[3]= [image]
```

---

``VertexCoordinates`` has higher priority than ``GraphLayout`` :

```wl
In[1]:= HypercubeGraph[3, VertexCoordinates -> Table[{i, i}, {i, 8}], GraphLayout -> "CircularEmbedding"]

Out[1]= [image]
```

#### VertexLabels (13)

Use vertex names as labels:

```wl
In[1]:= HypercubeGraph[3, VertexLabels -> "Name"]

Out[1]= [image]
```

---

Label individual vertices:

```wl
In[1]:= HypercubeGraph[3, VertexLabels -> {2 -> "one"}]

Out[1]= [image]
```

---

Label all vertices:

```wl
In[1]:= HypercubeGraph[3, VertexLabels -> Table[i -> Subscript[v, i], {i, 8}]]

Out[1]= [image]
```

---

Use any expression as a label:

```wl
In[1]:= HypercubeGraph[3, VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}]

Out[1]= [image]
```

---

Use ``Placed`` with symbolic locations to control label placement, including outside positions:

```wl
In[1]:= Table[HypercubeGraph[2, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■", p], {i, 4}], PlotLabel -> p], {p, {Before, After, Below, Above}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Symbolic outside corner positions:

```wl
In[1]:= pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};

In[2]:= Table[HypercubeGraph[2, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■", p], {i, 4}], PlotLabel -> p], {p, pl}]

Out[2]= {[image], [image], [image], [image]}
```

---

Symbolic inside positions:

```wl
In[1]:= Table[HypercubeGraph[2, VertexSize -> 0.25, VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Symbolic inside corner positions:

```wl
In[1]:= pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};

In[2]:= Table[HypercubeGraph[2, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 4}], PlotLabel -> p], {p, pl}]

Out[2]= {[image], [image], [image], [image]}
```

---

Use explicit coordinates to place the center of labels:

```wl
In[1]:= Table[HypercubeGraph[2, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 4}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[1]= {[image], [image], [image]}
```

---

Place all labels at the upper-right corner of the vertex and vary the coordinates within the label:

```wl
In[1]:= Table[HypercubeGraph[2, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], {{1, 1}, p}], {i, 4}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[1]= {[image], [image], [image]}
```

---

Place multiple labels:

```wl
In[1]:= HypercubeGraph[3, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]

Out[1]= [image]
```

Any number of labels can be used:

```wl
In[2]:= HypercubeGraph[3, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]

Out[2]= [image]
```

---

Use the argument to ``Placed`` to control formatting including ``Tooltip``:

```wl
In[1]:= HypercubeGraph[3, VertexLabels -> Placed["Name", Tooltip]]

Out[1]= [image]
```

Or ``StatusArea``:

```wl
In[2]:= HypercubeGraph[3, VertexLabels -> Placed["Name", StatusArea]]

Out[2]= [image]
```

---

Use more elaborate formatting functions:

```wl
In[1]:= rotateLabel[lab_] := Rotate[lab, 45Degree]

In[2]:= HypercubeGraph[3, VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 4}]]

Out[2]= [image]

In[3]:= panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Yellow, 0.7]]

In[4]:= HypercubeGraph[3, VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 4}]]

Out[4]= [image]

In[5]:= hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]

In[6]:= HypercubeGraph[3, VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 4}]]

Out[6]= [image]
```

#### VertexShape (5)

Use any ``Graphics``, ``Image``, or ``Graphics3D`` as a vertex shape:

```wl
In[1]:= Table[HypercubeGraph[3, VertexShape -> s, VertexSize -> Large], {s, {[image], [image], [image]}}]

Out[1]= {[image], [image], [image]}
```

---

Specify vertex shapes for individual vertices:

```wl
In[1]:= HypercubeGraph[3, VertexShape -> {2 -> [image]}, VertexSize -> Large]

Out[1]= [image]
```

---

``VertexShape`` can be combined with ``VertexSize``:

```wl
In[1]:= Table[HypercubeGraph[3, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Medium, Large}}]

Out[1]= {[image], [image]}
```

---

``VertexShape`` is not affected by ``VertexStyle``:

```wl
In[1]:= HypercubeGraph[3, VertexSize -> 0.4, VertexShape -> [image], VertexStyle -> Blue]

Out[1]= [image]
```

---

``VertexShapeFunction`` has higher priority than ``VertexShape`` :

```wl
In[1]:= HypercubeGraph[3, VertexSize -> 0.3, VertexShapeFunction -> "Square", VertexShape -> [image]]

Out[1]= [image]
```

#### VertexShapeFunction (10)

Get a list of built-in collections for ``VertexShapeFunction``:

```wl
In[1]:= ResourceData["VertexShapeFunction"]

Out[1]= {"Capsule", "Circle", "ConcaveDiamond", "ConcaveHexagon", "ConcavePentagon", "ConcaveSquare", "ConcaveTriangle", "Diamond", "DownTrapezoid", "FiveDown", "Hexagon", "Octagon", "Parallelogram", "Pentagon", "Point", "Rectangle", "RoundedDiamond", "RoundedDownTrapezoid", "RoundedFiveDown", "RoundedHexagon", "RoundedParallelogram", "RoundedPentagon", "RoundedRectangle", "RoundedSquare", "RoundedTriangle", "RoundedUpTrapezoid", "Square", "Star", "Triangle", "UpTrapezoid"}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Basic"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Basic"]

Out[1]= {"Capsule", "Circle", "Diamond", "DownTrapezoid", "FiveDown", "Hexagon", "Octagon", "Parallelogram", "Pentagon", "Point", "Rectangle", "Square", "Star", "Triangle", "UpTrapezoid"}
```

Simple basic shapes:

```wl
In[2]:= Table[HypercubeGraph[2, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]

Out[2]= {[image], [image], [image], [image], [image], [image]}
```

Common basic shapes:

```wl
In[3]:= Table[HypercubeGraph[2, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]

Out[3]= {[image], [image], [image], [image], [image], [image], [image], [image]}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Rounded"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Rounded"]

Out[1]= {"RoundedDiamond", "RoundedDownTrapezoid", "RoundedFiveDown", "RoundedHexagon", "RoundedParallelogram", "RoundedPentagon", "RoundedRectangle", "RoundedSquare", "RoundedTriangle", "RoundedUpTrapezoid"}

In[2]:= Table[HypercubeGraph[2, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]

Out[2]= {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Concave"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Concave"]

Out[1]= {"ConcaveDiamond", "ConcaveHexagon", "ConcavePentagon", "ConcaveSquare", "ConcaveTriangle"}

In[2]:= Table[HypercubeGraph[2, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]

Out[2]= {[image], [image], [image], [image], [image]}
```

---

Draw individual vertices:

```wl
In[1]:= HypercubeGraph[3, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]

Out[1]= [image]
```

Combine with a default vertex function:

```wl
In[2]:= HypercubeGraph[3, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]

Out[2]= [image]
```

---

Draw vertices using a predefined graphic:

```wl
In[1]:= HypercubeGraph[3, VertexShapeFunction -> (Inset[[image], #]&)]

Out[1]= [image]
```

---

Draw vertices by running a program:

```wl
In[1]:=
vf[{xc_, yc_}, name_, {w_, h_}] := 
	Block[{xmin = xc - w, xmax = xc + w, ymin = yc - h, ymax = yc + h}, 
	Polygon[{{xmin, ymin}, {xmax, ymax}, {xmin, ymax}, {xmax, ymin}}]
	];

In[2]:= HypercubeGraph[3, VertexShapeFunction -> vf, VertexSize -> 0.2]

Out[2]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexStyle``:

```wl
In[1]:= vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]

In[2]:= HypercubeGraph[3, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]

Out[2]= [image]
```

``VertexShapeFunction`` has higher priority than ``VertexStyle``:

```wl
In[3]:= vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}

In[4]:= HypercubeGraph[3, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]

Out[4]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexSize``:

```wl
In[1]:= HypercubeGraph[3, VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]

Out[1]= [image]
```

---

``VertexShapeFunction`` has higher priority than ``VertexShape``:

```wl
In[1]:= HypercubeGraph[3, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]

Out[1]= [image]
```

#### VertexSize (8)

By default, the size of vertices is computed automatically:

```wl
In[1]:= HypercubeGraph[3, VertexSize -> Automatic]

Out[1]= [image]
```

---

Specify the size of all vertices using symbolic vertex size:

```wl
In[1]:= Table[HypercubeGraph[3, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Use a fraction of the minimum distance between vertex coordinates:

```wl
In[1]:= Table[HypercubeGraph[3, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]

Out[1]= {[image], [image], [image], [image]}
```

---

Use a fraction of the overall diagonal for all vertex coordinates:

```wl
In[1]:= Table[HypercubeGraph[3, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]

Out[1]= {[image], [image], [image], [image]}
```

---

Specify size in both the $x$ and $y$ directions:

```wl
In[1]:= Table[HypercubeGraph[3, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]

Out[1]= {[image], [image]}
```

---

Specify the size for individual vertices:

```wl
In[1]:= HypercubeGraph[3, VertexSize -> {1 -> 0.2, 2 -> 0.3}]

Out[1]= [image]
```

---

``VertexSize`` can be combined with ``VertexShapeFunction`` :

```wl
In[1]:= Table[HypercubeGraph[3, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]

Out[1]= {[image], [image], [image]}
```

---

``VertexSize`` can be combined with ``VertexShape`` :

```wl
In[1]:= Table[HypercubeGraph[3, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]

Out[1]= {[image], [image], [image]}
```

#### VertexStyle (5)

Style all vertices:

```wl
In[1]:= Table[HypercubeGraph[3, VertexStyle -> style, VertexSize -> 0.3, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]

Out[1]= {[image], [image]}
```

---

Style individual vertices:

```wl
In[1]:= HypercubeGraph[3, VertexStyle -> {1 -> Blue, 2 -> Red}, VertexSize -> 0.3]

Out[1]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexStyle``:

```wl
In[1]:= vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]

In[2]:= HypercubeGraph[3, VertexSize -> 0.3, VertexStyle -> Blue, VertexShapeFunction -> vf1]

Out[2]= [image]
```

``VertexShapeFunction`` has higher priority than ``VertexStyle``:

```wl
In[3]:= vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}

In[4]:= HypercubeGraph[3, VertexSize -> 0.3, VertexStyle -> Blue, VertexShapeFunction -> vf2]

Out[4]= [image]
```

---

``VertexStyle`` can be combined with ``BaseStyle``:

```wl
In[1]:= HypercubeGraph[3, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.3]

Out[1]= [image]
```

``VertexStyle`` has higher priority than ``BaseStyle``:

```wl
In[2]:= HypercubeGraph[3, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.3]

Out[2]= [image]
```

---

``VertexShape`` is not affected by ``VertexStyle``:

```wl
In[1]:= HypercubeGraph[3, VertexSize -> 0.3, VertexShape -> [image], VertexStyle -> Blue]

Out[1]= [image]
```

#### VertexWeight (2)

Set the weight for all vertices:

```wl
In[1]:= HypercubeGraph[2, VertexWeight -> {2, 3, 4, 5}]

Out[1]= [image]

In[2]:= AnnotationValue[{%, 1}, VertexWeight]

Out[2]= 2
```

---

Use any numeric expression as a weight:

```wl
In[1]:= HypercubeGraph[2, VertexWeight -> {a, b, c, d}]

Out[1]= [image]

In[2]:= AnnotationValue[{%, 1}, VertexWeight]

Out[2]= a
```

### Applications (6)

The ``GraphCenter`` of hypercube graphs:

```wl
In[1]:= Table[HighlightGraph[#, GraphCenter[#]]&[HypercubeGraph[i, VertexSize -> 0.2]], {i, 2, 5}]

Out[1]= {[image], [image], [image], [image]}
```

---

The ``GraphPeriphery`` :

```wl
In[1]:= Table[HighlightGraph[#, GraphPeriphery[#]]&[HypercubeGraph[i, VertexSize -> 0.2]], {i, 2, 5}]

Out[1]= {[image], [image], [image], [image]}
```

---

The ``VertexEccentricity`` :

```wl
In[1]:= VertexEccentricity[HypercubeGraph[3], #]& /@ VertexList[HypercubeGraph[3]]

Out[1]= {3, 3, 3, 3, 3, 3, 3, 3}
```

Highlight the vertex eccentricity path:

```wl
In[2]:=
FindVertexEccentricityPath[g_ ? UndirectedGraphQ, u_] /; MemberQ[VertexList[g], u] := Module[{d = GraphDistanceMatrix[g], posu, posv, vl = VertexList[g]}, posu = VertexIndex[g, u];
	posv = First@First@Position[d[[posu]], Max[d[[posu]]]];
	PathGraph[FindShortestPath[g, u, vl[[posv]]]]]

In[3]:= Table[HighlightGraph[g = HypercubeGraph[3], FindVertexEccentricityPath[g, u]], {u, Range[4]}]

Out[3]= {[image], [image], [image], [image]}
```

---

The ``GraphRadius`` :

```wl
In[1]:= Table[GraphRadius[HypercubeGraph[i]], {i, 2, 5}]

Out[1]= {2, 3, 4, 5}
```

Highlight the radius path:

```wl
In[2]:=
FindRadiusPath[g_ ? UndirectedGraphQ] := Module[{c = First@GraphCenter[g], d, v, pos}, d = Table[GraphDistance[g, c, u], {u, VertexList[g]}];
	pos = First@Position[d, Max[d]];
	v = First@Part[VertexList[g], pos];
	PathGraph[FindShortestPath[g, c, v]]]

In[3]:= Table[HighlightGraph[#, FindRadiusPath[#]]&[HypercubeGraph[i, VertexSize -> Tiny]], {i, 2, 5}]

Out[3]= {[image], [image], [image], [image]}
```

---

The ``GraphDiameter`` :

```wl
In[1]:= Table[GraphDiameter[HypercubeGraph[i]], {i, 2, 5}]

Out[1]= {2, 3, 4, 5}
```

Highlight the diameter path:

```wl
In[2]:=
FindDiameterPath[g_ ? UndirectedGraphQ] := Module[{d = GraphDistanceMatrix[g], u, v, pos}, pos = First@Position[d, Max[d]];
	{u, v} = Part[VertexList[g], pos];
	PathGraph[FindShortestPath[g, u, v]]]

In[3]:= Table[HighlightGraph[#, FindDiameterPath[#]]&[HypercubeGraph[i, VertexSize -> Tiny]], {i, 2, 5}]

Out[3]= {[image], [image], [image], [image]}
```

---

Highlight the vertex degree for ``HypercubeGraph`` :

```wl
In[1]:= HighlightCentrality[g_, cc_] := HighlightGraph[g, Table[Style[VertexList[g][[i]], ColorData["TemperatureMap"][cc[[i]] / Max[cc]]], {i, VertexCount[g]}]];

In[2]:= g = HypercubeGraph[3, VertexSize -> Large];

In[3]:= HighlightCentrality[g, VertexDegree[g]]

Out[3]= [image]
```

Highlight the closeness centrality:

```wl
In[4]:= HighlightCentrality[g, ClosenessCentrality[g]]

Out[4]= [image]
```

Highlight the eigenvector centrality:

```wl
In[5]:= HighlightCentrality[g, EigenvectorCentrality[g]]

Out[5]= [image]
```

### Properties & Relations (6)

``HypercubeGraph[n]`` has $2^n$ vertices:

```wl
In[1]:= VertexCount[HypercubeGraph[n]]

Out[1]= 2^n
```

---

``HypercubeGraph[n]`` has $n 2^{n-1}$ edges:

```wl
In[1]:= EdgeCount[HypercubeGraph[n]]

Out[1]= 2^-1 + n n
```

---

Hypercube graph $Q_2$ is a cycle graph $C_4$ :

```wl
In[1]:= HypercubeGraph[2]

Out[1]= [image]
```

---

Hypercube graph is bipartite:

```wl
In[1]:= BipartiteGraphQ[HypercubeGraph[3]]

Out[1]= True
```

---

Hypercube graph is Hamiltonian:

```wl
In[1]:= HamiltonianGraphQ[HypercubeGraph[4]]

Out[1]= True
```

---

The eigenvalues of the adjacency matrix of a hypercube graph are $-n,2-n,\ldots , --2, 0, 2,\ldots , n-2, n$ :

```wl
In[1]:= Eigenvalues[AdjacencyMatrix[HypercubeGraph[4]]]//Sort

Out[1]= {-4, -2, -2, -2, -2, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 4}
```

### Possible Issues (1)

The setting ``DirectedEdges -> True`` does not apply to ``HypercubeGraph`` :

```wl
In[1]:= HypercubeGraph[3, DirectedEdges -> True]

Out[1]= [image]
```

### Neat Examples (2)

```wl
In[1]:= Table[HypercubeGraph[k], {k, 5, 8}]

Out[1]= {[image], [image], [image], [image]}
```

---

```wl
In[1]:= MatrixPlot[AdjacencyMatrix[HypercubeGraph[17]]]

Out[1]= [image]
```

## See Also

* [`Graph`](https://reference.wolfram.com/language/ref/Graph.en.md)
* [`GraphData`](https://reference.wolfram.com/language/ref/GraphData.en.md)
* [`CompleteGraph`](https://reference.wolfram.com/language/ref/CompleteGraph.en.md)

## Related Guides

* [Graph Construction & Representation](https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md)

## Related Links

* [An Elementary Introduction to the Wolfram Language: Graphs and Networks](https://www.wolfram.com/language/elementary-introduction/21-graphs-and-networks.html)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md)