Skip to content
Azhimathi Mayam logoDSA Study HubPCCST303 · KTU · S3
Module 3 · syllabusLesson live

Graph definitions

Vertices, edges and the vocabulary — directed, undirected, degree, path, cycle, connected, weighted.

Syllabus says: “Graphs: Definitions”

On this page · 7 sections
ormakkurippu ✎
Never-forget card

Sum of all degrees = 2 × edges (each edge has two ends). Complete graph on n vertices has n(n − 1)/2 edges.

Picture it

Kerala's district map: districts are vertices, roads between them are edges, distances are weights, and a one-way road is a directed edge.

Write this in the exam

A graph G = (V, E) consists of a finite non-empty set of vertices V and a set of edges E, where each edge connects a pair of vertices; the pairs are ordered in a directed graph and unordered in an undirected graph.

What you will be able to do

  • Define graphs and their types.
  • Use the terms degree, path, cycle, connected, component and weighted graph.

Terminology

TermMeaning
Undirected graphedge (u, v) is the same as (v, u)
Directed graph (digraph)edge <u, v> goes from u (tail) to v (head)
Adjacentu and v are adjacent if an edge joins them
Degreenumber of edges at a vertex; digraphs have in-degree and out-degree
Patha sequence of vertices with an edge between each consecutive pair
Simple patha path with no repeated vertices
Cyclea simple path whose first and last vertices are the same
Connected (undirected)there is a path between every pair of vertices
Strongly connected (directed)there is a directed path from every vertex to every other
Connected componenta maximal connected subgraph
Complete graphevery pair of vertices is adjacent: n(n − 1)/2 edges (undirected)
Weighted graph (network)each edge carries a number (cost, distance, time)
SubgraphG′ = (V′, E′) with V′ ⊆ V and E′ ⊆ E
ABCD
Undirected: deg(A) = 2, deg(B) = 2, deg(C) = 3, deg(D) = 1. Sum 8 = 2 × 4 edges. A–B–C–A is a cycle.
123
Directed: each vertex has in-degree 1 and out-degree 1. Strongly connected — you can go round the loop.
Pro tipHandshake lemma

Σ degree(v) = 2|E| in an undirected graph, because each edge adds 1 to the degree of both its ends. In a digraph, Σ in-degree = Σ out-degree = |E|.

Graphs everywhere

  • Road and rail networks (shortest routes).
  • Social networks (friends of friends).
  • Web pages and links (search engines).
  • Task dependencies in a project (directed acyclic graphs).

Quick check — can you get them all?

Question 1

Q1.An undirected graph has degrees 3, 2, 2, 1. Number of edges?

Question 2

Q2.Maximum edges in an undirected graph with 6 vertices (no loops)?

Question 3

Q3.A path that starts and ends at the same vertex, with no other repeats, is a…

Practice

Every visualizer has a Practice mode: predict the next state before the animation reveals it. You can also work through the topic's question set on the practice page.

Exam-ready summary

  • G = (V, E); directed vs undirected; weighted.
  • Degree, path, simple path, cycle, connected, strongly connected, component.
  • Σ degrees = 2|E|; complete graph has n(n − 1)/2 edges.

References

  • Horowitz, Sahni & Anderson-Freed, Fundamentals of Data Structures in C, 2/e — §6.1 (The graph abstract data type)
  • Cormen, Leiserson, Rivest & Stein, Introduction to Algorithms, 3/e — Appendix B.4

Explanations on this page are original. Textbook references point to where the standard treatment can be read; no text is reproduced from them.

Prefer revising from notes? Module-wise notes and question papers on Azhimathi Mayam (opens in a new tab)