liveBook · Manning

Node

As explained in Grokking Data Structures

A vertex is a node in a graph that represents an entity or endpoint of relationships.

Picture a friendship network: each person is a point, and a connection between two people shows a relationship. In a graph, that point is called a vertex, or node. Vertices represent distinct entities; edges connect pairs of vertices. section 13.2 section 13.3

An edge has two endpoints: a source vertex and a destination vertex. In a directed graph, you can follow the edge only from source to destination; an undirected edge works both ways. This matters when choosing a model: following someone need not be mutual, while a friendship can be represented as a two-way connection. section 13.2 section 13.4

A small friendship graph

Suppose the first two animals in a social network are a campaigner and her friend. Represent each animal as a vertex and their friendship as an edge. Adding animals adds vertices; recording their friendships adds edges. section 13.3

G = ([v1, v2, v3, v4], [(v1,v2),(v1,v3),(v2,v4)])

The listing writes a graph as a collection of vertices paired with a collection of edges. Each edge is shown as a pair of vertex names. section 13.2

“Node” also appears in other data structures, but its links have a different job there. A linked-list node stores a value and a link to the next node. A tree node stores a value and links to children. A graph vertex is an entity in a set of vertices; edges describe its relationships with other vertices. section 6.6 section 11.2 section 13.2

Once vertices and edges are identified, you can ask whether vertices are connected or seek a path between them. Breadth-first search finds paths with the fewest edges from a starting vertex; depth-first search follows paths to their ends and can help check graph properties. section 13.16

How Grokking Data Structures covers it

How deep it goes
Defines vertices as a set and edges as endpoint pairs, then explains edge direction without prescribing a vertex class.
Examples
Uses an animal friendship network and contrasts one-way social-media follows with two-way friendships.
What it assumes
Introduces vertices and edges through definitions and a friendship scenario rather than requiring prior graph terminology.
What you can do after
Evaluate/understand it by identifying graph vertices and choosing edge direction to represent a relationship.
How it connects
Connects vertices to edges, directed graphs, undirected graphs, trees, and graph traversal.

Also explained in

Compare how 19 books explain node →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Data Structures. The section links point to the parts of the book it draws on.