Graphs

Terminology

node

A point or vertice on the graph. (Also stated as V)

edge

The connection between two nodes. (Also stated as E)

connected

When every node has a path to another node.

cycle

When you start at NodeXNode_X, follow the links, and end back at NodeXNode_X. (Can't be only 2 nodes)

acyclic

A graph that contains no cycles.

directed

When there is a direction to the connections. (This helps making asymetric connections, Ex.: A10BA \rightarrow_{10} B but B20AB \rightarrow_{20} A)

undirected

Not directed. (The default) (Ex.: ABA \rightarrow B has the same weight as BA)B \rightarrow A)

weighted

The edges have a weight associated with them.

dag

Directed, acyclic graph.

Representing Graphs

Adjacent List

A list, where each main index of the list points to a node of the graph, describing its connections to the other nodes.

circle-info

This representation is more commonly used.

Drawing

Traversing/Searching with BFS

Traversing/Searching with DFS

Easier to preserve the path.

circle-info

Runs on O(V+E)O(V+E).

Adjacent Matrix

A matrix, where each main index of the first array points to a node of the graph, describing in a second array the weights to the other nodes or zero if there is no connection.

triangle-exclamation
Drawing

Traversing/Searching with BFS

Last updated