---
title: "VertexComponent"
language: "en"
type: "Symbol"
summary: "VertexComponent[g, {v1, v2, ...}] gives the vertices in the graph g that have a path to at least one of v1, v2, ... . VertexComponent[g, {v1, v2, ...}, k] gives the vertices with a path to at least one of v1, v2, ... of at most length k. VertexComponent[g, {v1, v2, ...}, {k}] gives the vertices at length exactly k. VertexComponent[{v -> w, ...}, ...] uses rules v -> w to specify the graph g."
keywords: 
- reachable vertices
- vertices of distance k
- connected component
canonical_url: "https://reference.wolfram.com/language/ref/VertexComponent.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Graph Components and Connectivity"
    link: "https://reference.wolfram.com/language/guide/GraphComponents.en.md"
related_functions: 
  - 
    title: "VertexInComponent"
    link: "https://reference.wolfram.com/language/ref/VertexInComponent.en.md"
  - 
    title: "VertexOutComponent"
    link: "https://reference.wolfram.com/language/ref/VertexOutComponent.en.md"
  - 
    title: "NeighborhoodGraph"
    link: "https://reference.wolfram.com/language/ref/NeighborhoodGraph.en.md"
  - 
    title: "ConnectedComponents"
    link: "https://reference.wolfram.com/language/ref/ConnectedComponents.en.md"
  - 
    title: "KCoreComponents"
    link: "https://reference.wolfram.com/language/ref/KCoreComponents.en.md"
---
# VertexComponent

VertexComponent[g, {v1, v2, …}] gives the vertices in the graph g that have a path to at least one of v1, v2, … .

VertexComponent[g, {v1, v2, …}, k] gives the vertices with a path to at least one of v1, v2, … of at most length k.

VertexComponent[g, {v1, v2, …}, {k}] gives the vertices at length exactly k.

VertexComponent[{v -> w, …}, …] uses rules v -> w to specify the graph g.

## Details

[image]

* ``VertexComponent`` works for any undirected graph object.

* ``VertexComponent`` works with undirected graphs, directed graphs, multigraphs, and mixed graphs.

## Examples (9)

### Basic Examples (1)

Find the component of a vertex in a graph:

```wl
In[1]:= g = [image];

In[2]:= VertexComponent[g, {1}]

Out[2]= {1, 2, 6, 3, 7, 8}
```

Highlight the component of a vertex:

```wl
In[3]:= HighlightGraph[g, %]

Out[3]= [image]
```

### Scope (8)

``VertexComponent`` works with undirected graphs:

```wl
In[1]:= VertexComponent[[image], {1}]

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

---

Directed graphs:

```wl
In[1]:= VertexComponent[[image], {2}]

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

---

Multigraphs:

```wl
In[1]:= VertexComponent[[image], {2}]

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

---

Mixed graphs:

```wl
In[1]:= VertexComponent[[image], {2}]

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

---

Use rules to specify the graph:

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

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

---

Use patterns to select a subset of vertices:

```wl
In[1]:= VertexComponent[[image], _ ? EvenQ]

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

---

Find the component connected to a vertex by a path of at most length 2 in a graph:

```wl
In[1]:= VertexComponent[[image], 8, 2]

Out[1]= {8, 6, 7, 4, 5}
```

---

``VertexComponent`` works with large graphs:

```wl
In[1]:= g = GridGraph[{10, 10, 10, 10}];

In[2]:= VertexComponent[g, {1}] //Length// Timing

Out[2]= {0.012201, 10000}
```

## See Also

* [`VertexInComponent`](https://reference.wolfram.com/language/ref/VertexInComponent.en.md)
* [`VertexOutComponent`](https://reference.wolfram.com/language/ref/VertexOutComponent.en.md)
* [`NeighborhoodGraph`](https://reference.wolfram.com/language/ref/NeighborhoodGraph.en.md)
* [`ConnectedComponents`](https://reference.wolfram.com/language/ref/ConnectedComponents.en.md)
* [`KCoreComponents`](https://reference.wolfram.com/language/ref/KCoreComponents.en.md)

## Related Guides

* [Graph Components and Connectivity](https://reference.wolfram.com/language/guide/GraphComponents.en.md)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md) \| [Updated in 2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) ▪ [2015 (10.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn103.en.md) ▪ [2020 (12.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn121.en.md)