algoritmauzmanı
Sign in
TREN
Subtopic 8.1

Graph with an Adjacency Matrix

5lessons32 min0done

An adjacency matrix keeps a graph with n vertices in an n×n two-dimensional array: if adj[u][v] is 1, there is an edge from u to v. Whether two vertices are joined is known at a glance, in O(1) time.

Each operation is its own lesson: creating the graph, adding and removing edges, listing neighbours and degree, breadth-first and depth-first search. The next subtopic repeats the same operations in the same order with adjacency lists.

Lesson 8.1.1 A graph in a matrix: creating it6 min