# Vertex

> The Vertex in Graph Theory is a fundamental element of a graph, representing a point where edges meet.

## What is a vertex in a graph?

The point or node in a graph where edges connect. They are used to represent entities and edges represent relationships between them.

- Topic: Graph
- Type: concept

## Example

Wrong:

```js
const graph = {};
for (const user of users) graph[user] = [];
```

Right:

```js
const graph = new Map();
for (const user of users) graph.set(user, []);
```

Plain object keys become strings, so object vertices collide; a `Map` keeps each object as its own key.

## Common mistakes

- Building the graph only from edges and losing vertices that have no edges.
- Using objects as keys of a plain object, so every vertex becomes '[object Object]'.

## Key points

- Vertices are keys in a `Map` of adjacency lists, not items in an array searched with `indexOf()`.
- Vertices with no edges are stored too, so they appear in traversals and counts.

## Interview questions

### What is the degree of a vertex?

The number of edges touching it. In a directed graph, in-degree counts incoming edges and out-degree counts outgoing ones.

### Vertex vs node: are they the same?

In graph theory they mean the same thing. Vertex is the math term; node is more common in code and in trees.

## Related cards

- [Edge](https://wonderium.dev/algorithms/edge.md)
- [Graph](https://wonderium.dev/algorithms/graph.md)
- [Node](https://wonderium.dev/algorithms/node.md)
- [Depth-First Search](https://wonderium.dev/algorithms/depth-first-search.md)
- [Map](https://wonderium.dev/js/map.md)

---

- Level: [Algorithms](https://wonderium.dev/algorithms.md)
- HTML version: https://wonderium.dev/algorithms/vertex
- Last updated: 2026-11-25
