Trusted answers to developer questions

Directed Graphs vs. Undirected Graphs

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

Directed Graphs

A directed graph is a set of vertices (nodes) connected by edges, with each node having a direction associated with it.

Edges are usually represented by arrows pointing in the direction the graph can be traversed.

In the example on the right, the graph can be traversed from vertex A to B, but not from vertex B to A.

svg viewer

Undirected Graphs

In an undirected graph the edges are bidirectional, with no direction associated with them. Hence, the graph can be traversed in either direction. The absence of an arrow tells us that the graph is undirected.

svg viewer

In the example on the left, the graph can be traversed from node A to B as well as from node B to A.

Some more complex directed and undirected graphs might look like the following:

Directed Graph
Directed Graph
Undirected Graph
Undirected Graph

RELATED TAGS

graph
data structures
undirected graph
directed graph
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?