Graph Basics

COMP2521 20T2 ♢ Graph Basics [0/15]
❖ Graphs

Many applications require

Examples: Collection types you're familiar with Graphs are more general … allow arbitrary connections
COMP2521 20T2 ♢ Graph Basics [1/15]
❖ ... Graphs

A graph G = (V,E)

Example:

[Diagram:Pics/graph1.png]

COMP2521 20T2 ♢ Graph Basics [2/15]
❖ ... Graphs


Nodes are distinguished by a unique identifier

Edges may be (optionally) directed, labelled and/or weighted


[Diagram:Pics/graph-edges.png]

COMP2521 20T2 ♢ Graph Basics [3/15]
❖ ... Graphs

A real example: Australian road distances

Distance Adelaide Brisbane Canberra Darwin Melbourne Perth     Sydney
Adelaide -20551390305173227161605
Brisbane 2055-1291342916714771982
Canberra 13901291-44416584106309
Darwin 305134294441-378340494411
Melbourne 73216716583783-3448873
Perth 27164771410640493448-3972
Sydney 160598230944118733972-

Notes: vertices are cities, edges are distance between cities, symmetric

COMP2521 20T2 ♢ Graph Basics [4/15]
❖ ... Graphs

Alternative representation of above:

[Diagram:Pics/ausroads.png]

COMP2521 20T2 ♢ Graph Basics [5/15]
❖ ... Graphs

Questions we might ask about a graph:

Graph algorithms are generally more complex than tree/list ones:
COMP2521 20T2 ♢ Graph Basics [6/15]
❖ Properties of Graphs

Terminology: |V| and |E| (cardinality) normally written just as V and E.

A graph with V  vertices has at most V(V-1)/2 edges.

The ratio E:V can vary considerably.

Knowing whether a graph is sparse or dense is important

COMP2521 20T2 ♢ Graph Basics [7/15]
❖ Graph Terminology


For an edge e that connects vertices v  and w

Degree of a vertex v
Synonyms:
COMP2521 20T2 ♢ Graph Basics [8/15]
❖ ... Graph Terminology

Path: a sequence of vertices where

Cycle: a path where Length of path or cycle = #edges

[Diagram:Pics/pc-graphs.png]

COMP2521 20T2 ♢ Graph Basics [9/15]
❖ ... Graph Terminology

Connected graph

Complete graph KV

[Diagram:Pics/complete-graphs.png]

COMP2521 20T2 ♢ Graph Basics [10/15]
❖ ... Graph Terminology

Tree: connected (sub)graph with no cycles

Spanning tree: tree containing all vertices

Clique: complete subgraph

Consider the following single graph:

[Diagram:Pics/graph2.png]

This graph has 25 vertices, 32 edges, and 4 connected components

Note: The entire graph has no spanning tree; what is shown in green is a spanning tree of the third connected component

COMP2521 20T2 ♢ Graph Basics [11/15]
❖ ... Graph Terminology


A spanning tree of connected graph G = (V,E)

A spanning forest of non-connected graph G = (V,E)
COMP2521 20T2 ♢ Graph Basics [12/15]
❖ ... Graph Terminology

Can form spanning tree from graph by removing edges

[Diagram:Pics/span-tree.png]


Many possible spanning trees can be formed. Which is "best"?

COMP2521 20T2 ♢ Graph Basics [13/15]
❖ ... Graph Terminology

Undirected graph

Directed graph Examples:

[Diagram:Pics/ud-graphs.png]

COMP2521 20T2 ♢ Graph Basics [14/15]
❖ ... Graph Terminology

Other types of graphs …

Weighted graph

Multi-graph Labelled graph
COMP2521 20T2 ♢ Graph Basics [15/15]


Produced: 21 Jun 2020