Trees describe hierarchies, where every item has one parent. Many real relationships are not hierarchical: two cities can be joined by several roads, and you can drive round in a circle. Graphs describe such general relationships.
What a graph is
For example, the graph of Figure 8.1 has V={1,2,3,4,5} and E={(1,2),(1,5),(1,3),(5,4),(4,3),(2,3)}. We write n=∣V∣ and e=∣E∣.
In an undirected graph an edge is an unordered pair: (1,5) and (5,1) are the same edge.
In a directed graph (digraph) an edge is an ordered pair (u,v), drawn as an arrow from u to v; (1,5) and (5,1) are different edges.
In a weighted graph each edge has a number (cost, distance, time) called its weight.
Terms
Term
Meaning
Adjacent
u and v are adjacent if there is an edge between them
Degree
Number of edges at a vertex; in a digraph, in-degree (arrows in) and out-degree (arrows out)
Path
A sequence of vertices v0,v1,…,vk in which each consecutive pair is joined by an edge; its length is k, the number of edges
Simple path
A path in which all vertices are different (except possibly the first and last)
Cycle
A path of length at least 1 with v0=vk (simple, apart from the repeated end)
Loop
An edge (v,v) from a vertex to itself
Acyclic graph
A graph with no cycles; a directed acyclic graph is called a DAG
Spanning tree
A tree containing all n vertices and n−1 edges of the graph
In an undirected graph the degrees add up to twice the number of edges, because every edge has two ends: ∑deg(v)=2e.
Connectivity
An undirected graph is connected if there is a path between every pair of vertices.
A digraph is strongly connected if for every pair of vertices u,v there is a path from u to vand a path from v to u.
A digraph is weakly connected if it is connected when the directions are ignored, but not strongly connected.
A complete graph has an edge between every pair of distinct vertices: an undirected complete graph on n vertices has 2n(n−1) edges.
Key takeaways
G=(V,E): vertices and edges; undirected (unordered pairs) or directed (ordered pairs); possibly weighted.
Path length = number of edges; a cycle starts and ends at the same vertex.
In an undirected graph ∑deg(v)=2e; a complete graph has n(n−1)/2 edges.
Strongly connected: directed paths in both directions between every pair.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Define a directed graph, an undirected graph, a path, a cycle and a strongly connected graph, with a small example of each.
Show worked answer
A directed graph is G=(V,E) in which each edge is an ordered pair (u,v), drawn as an arrow (e.g. V = {a, b, c}, E = {(a,b), (b,c)}). An undirected graph has unordered edges, so (u,v)=(v,u) (e.g. a triangle a–b–c–a). A path is a sequence of vertices in which each consecutive pair is joined by an edge (a, b, c). A cycle is a path of length ≥ 1 whose first and last vertices are equal (a, b, c, a in the triangle). A digraph is strongly connected if every vertex can reach every other vertex by a directed path (e.g. a→b, b→c, c→a).
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/graphs/graphs-definitions-and-terminology/ to read this page.