📚 Seth MB

Search

Search IconIcon to open search

Graphs

Last updated Jul 12, 2023 Edit

Graphs are used to represent data visually. They require relations between the data.

Circles or nodes are called vertices and the lines between them are called edges.

Larger graphs might look like this:

If an edge has a value associated with it, such as 6, then that edge is weighted. Typically, if one edge is weighted, you would expect all other edges to have a weight. You can describe a graph that includes weights, intuitively, as a weighted graph.

You can also represent data from a graph as an adjacency matrix

If a graph would be symmetrical, so all weighted values are equivalent both ways (so A to B and B to A both have a value of 5), then you only need to complete half of the graph, giving you a triangular shape to your adjacency matrix.

The graph below only defines one value for each route, meaning it would be symmetrical.

Data can also be represented as an adjacency list, such as the one shown below.

An adjacency list makes more sense when there are few connections between vertices as it will use less space.

A cycle occurs if you can move from a vertex without crossing an edge twice.

A tree is another kind of graph.

To be a tree, a graph must:

A tree will have a root, which is designated.

The vertexes at the end of a tree are called leaves, whilst the edges between vertexes are called branches.

# Binary Trees

# Constructing a tree

# Tree traversal

# Pre-order

# In-order

# Post-order

And time for the beautiful hand-drawn tree, with sorted examples.

# Storing a binary tree

# Linked list

Computer Science