Lesson 11 — Intermediate

Graph Theory Basics

Graph theory discrete maths ka sabse visual aur practical topic hai — stations aur tracks, users aur friendships, sab graph hain. Is lesson mein seekhenge graph kya hota hai, degree aur handshaking lemma, types of graphs, aur Euler circuit ki condition. GATE ka sabse scoring section yahi hai.

⏱ 15 min• Intermediate• Recurrence Relations

Graph kya hai

WHAT

Graph G = (V, E) hai — V = vertices (nodes), E = edges (inke beech ke connections). Undirected graph mein edge do taraf chalti hai, directed graph (digraph) mein ek taraf (arrow).

WHEN

Koi bhi network ho — social media, roads, dependency, state machines — usko graph bolte hain. Path dhoondhna, cycle detect karna, sab graph algorithms hain.

WHERE

Google Maps (stations = vertices), WhatsApp (users = vertices), BFS/DSA, databases (joins) — graphs CS ki sabse practical maths hai.

Ek graph ka size do numbers se banta hai: |V| (vertices) aur |E| (edges). Degree = har vertex ki incident edges ki ginti. Inhi numbers se aage ke sare formulas bante hain.

Degree aur Handshaking Lemma

Degree deg(v) = vertex ki incident edges ki ginti

Handshaking Lemma (GATE ka favourite):
  Σ deg(v) = 2|E|
  (har edge do vertices ko touch karti hai — 2 baar count)

Worked: 4 vertices, har ka degree 3 (yaani K4)
  Σ deg = 4 × 3 = 12  ⇒  |E| = 12 / 2 = 6  ✓

Directed graph mein:
  out-degree + in-degree = poora degree
  Σ out-deg = Σ in-deg = |E|

Corollary: odd degree wale vertices HAMESHA even
sankhya mein hote hain (ka total even rehna chahiye)
Instant check: Question mein degrees de rakhi hain? Multiply karke divide by 2 — edges mil gaye. Aur agar degree ka total ODD aaya toh data hi galat hai — handshaking lemma toot gaya, ye option reject karo.

Graph ke types

Types (GATE classification):
Simple graph   : no loop, no parallel edge
Multigraph     : parallel edges (do edges same pair pe)
Pseudograph    : loops + parallel edges dono
Weighted graph : edges pe number (distance, cost)

Complete graph K_n : har do vertices directly connected
  |E| = n(n−1)/2     K4 = 6 edges,  K5 = 10 edges

Regular graph : har vertex ka same degree (k-regular)
Bipartite     : V do groups mein, sirf cross-group edges
Complete bipartite K(m, n) : m × n edges
Planar graph  : plane mein bina edges cross kiye draw

Complete graph ka formula rat lo — n(n−1)/2. K5 = 10 edges ye har saal kahin na kahin aata hai. Bipartite graph theoretical questions (2-coloring) mein bhi aata hai.

Paths, cycles aur Euler graphs

Adjacency Matrix (undirected graph → symmetric):
     a b c
a  [ 0 1 1 ]
b  [ 1 0 1 ]
c  [ 1 1 0 ]   → 3 edges,  har row ka sum = degree = 2

EULER graph : ek trail mein sab edges (bina repeat kiye)
  Condition : connected + HAR vertex ka EVEN degree
  (Königsberg bridge problem — graph theory ki shuruat)

HAMILTONIAN : sab vertices EK BAAR (edges repeat allowed nahi)
  Koi aasan fixed condition nahi — NP-complete problem

Exercise

Question: 4 vertices hain, har vertex ka degree 3. Total edges kitne? Sirf number daalo.

Question: Euler circuit ke liye kya condition hai? (har vertex ka even degree / koi bhi vertex odd degree / koi condition nahi)

Question: K5 (complete graph, 5 vertices) mein kitne edges hain? Sirf number daalo.

Common mistakes

Desi example: Indian Railways ka network

Stations = vertices, direct tracks = edges. Chennai se Delhi direct train hai? — edge hai. Degree = junction pe kitni lines milti hain. Ring route = cycle. Sab graph theory:

text
Vertices : major stations (Delhi, Howrah, Chennai...)
Edges    : direct train routes
Degree   : Howrah jaisa junction = high degree node
Cycle    : Mumbai se Pune se Nagpur... wapas = ring route
Question : Delhi se Chennai shortest path = graph algorithm
Exam mapping (GATE / DSA interviews)
  • GATE: handshaking lemma + graph types — 1-2Q fixed.
  • DSA interviews: BFS/DFS, cycle detection isi basics par chalte hain.
  • Euler circuit condition GATE mein direct poochhi jaati hai.
  • Trap: "sum of degrees = |E|" — galat, 2|E| hai.
Lesson complete?

Graphs ka basics clear. Agla lesson — Trees & Spanning Trees — mein dekhenge graph ka sabse important special case (network ka backbone).

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course