Graph
Context: FIT1058_MOC · an abstract model of a network · a set of vertices plus edges · adjacency is a relation on vertices · FIT2004_MOC · the W5 data structure everything else reduces to — see Graph Representations, Uninformed Search (BFS and DFS), Dijkstra’s Algorithm
Quick Revision
- 🎯 Objective: : vertices + edges ➔ models which pairs interact; add direction and weight and it models cost, order and flow.
- 📦 Core Components: adjacency () ➔ incidence ➔ isolated/leaf vertices ➔ and the sparse/dense split.
- ⚡ Key Constraint: adjacency is a symmetric irreflexive Binary Relation in the undirected case only; specify both and , and say whether the graph is directed and weighted before quoting any bound.
📝 Core
1. The Graph, Adjacency and Incidence
- Definition ➔ ; vertices, edges (unordered pairs of distinct vertices) — models the structure of interactions, discarding all else.
- Adjacent ➔ iff (vertex–vertex) · incident ➔ vertex is an endpoint of an edge (vertex–edge).
- Special vertices ➔ isolated = in no edge (degree ) · leaf = in exactly one edge (degree ).
2. FIT2004 Formal Definitions (W5)
- Edge ➔ ; directed ⟹ the edge runs from to ; weighted ⟹ and the graph is written .
- Simple graph ➔ no self-edges and no multi-edges — the default assumption in every FIT2004 algorithm (Types of Graphs).
- Vertex node, edge link ➔ both naming pairs appear in the slides; treat them as synonyms.
- Everything reduces to a graph ➔ a Tree is a graph, a database is a graph, and problems such as longest common subsequence are solved by building a DAG — the transferable move is modelling the problem as , not memorising an algorithm (LO1).
- A Tree as a graph ➔ the root is the single vertex with no incoming edge; a binary tree caps out-degree at ; and there is no cycle.
3. Size Properties and the Sparse/Dense Split
- Notation ➔ vertices, edges; bounds are written in and with the bars dropped.
- Maximum edges ➔ directed · undirected — the halving is a constant factor, so both are .
- Sparse ➔ (typically ) · dense ➔ .
- Why it matters ➔ this one classification decides the representation, collapses into for Dijkstra’s Algorithm, and decides whether a Fibonacci heap is worth its constants.
- Worked example ➔ the World Wide Web: pages are vertices, hyperlinks edges, PageRank a traversal propagating authority — a huge, extremely sparse graph.
⚖️ Core Decision Matrix
| Term | Relates | Example |
|---|---|---|
| adjacency | vertex–vertex | |
| incidence | vertex–edge | in |
| isolated | degree 0 | |
| leaf | degree 1 |
When It Flips: adjacency is a symmetric, irreflexive Binary Relation on — the bridge to relation theory; Connectivity turns the walk relation into an Equivalence Relation. Graphs here are simple unless stated (Types of Graphs). Direction breaks the symmetry; weight breaks the "one hop one unit" assumption that BFS rests on.
📊 Exam Execution Trace
Manual Execution Trace
:
| Step / State | Query | Answer |
|---|---|---|
| 0 (Init) | — | — |
| 1 | neighbours of | |
| 2 | edges incident with | |
| 3 | classify | isolated |
Applied Exercise
Problem: a simple undirected graph has vertices and edges. Sparse or dense, and what follows?
Final Extracted Output: sparse () ➔ store it as an adjacency list at rather than a matrix at , and quote Dijkstra as rather than collapsing to .
⚠️ Common Mistakes
- 💡 Must give both and ➔ an isolated vertex leaves no trace in the edge list; in the undirected case edges are sets, so no vertex is adjacent to itself.
- 💡 Treating as “dense means directed” ➔ directed and undirected maxima differ only by ; density is about how many possible edges are actually present.
🧠 Active Recall
Define a graph, distinguish adjacency from incidence, and say why the vertex set must be recorded separately.
- Hint: Vertex–vertex vs vertex–edge; isolated vertices vanish from edges.
Answer
- Short answer: with edges as unordered pairs; adjacency relates two vertices (), incidence relates a vertex to an edge. An isolated vertex (degree ) appears in no edge, so the edge list alone would lose it.
- Why: The two relations answer different queries ➔ traversal asks for adjacency, degree counting asks for incidence, and neither recovers a vertex that participates in nothing.
Why does FIT2004 keep restating "sparse or dense?" before quoting a complexity?
- Hint: Two variables, one bounded by the square of the other.
Answer
- Short answer: because ranges from to , so a bound in is not a bound in until density is fixed.
- Why: Bounds carry two parameters ➔ is on a sparse graph and on a dense one, so “tightest bound” (Big-O Notation) is meaningless until you say which. The representation choice follows ➔ the adjacency list wins by an order of magnitude on sparse graphs (Graph Representations), and the Fibonacci-heap Dijkstra only pays off when .