PAVANXDCL • DSA

Learn Graphs

Learn graph fundamentals, BFS, DFS, shortest paths and classic graph algorithms through simple practice challenges.

01 — FOUNDATION

What is a Graph?

A graph is a collection of vertices connected by edges. It is useful for representing relationships between objects.

VerticesNodes / objects
→
EdgesConnections
→
TraversalBFS / DFS
→
ProblemsPaths / cycles

Vertex

An individual node or object in a graph.

Edge

A connection between two vertices.

Weight

A value such as distance, cost or time stored on an edge.

02 — REPRESENTATION

How We Store Graphs

Adjacency List

Each vertex stores its connected neighbors. Great for sparse graphs.

0 → 1, 2
1 → 0, 3
2 → 0
3 → 1

Adjacency Matrix

A 2D matrix stores whether an edge exists between every pair.

  0 1 2
0 0 1 1
1 1 0 0
2 1 0 0

Directed Graph

Edges have a direction. A → B does not necessarily mean B → A.

Undirected Graph

Edges have no direction. A connected to B means B is connected to A.

03 — GRAPH PATTERNS

BFS vs DFS

Choosing the right traversal is one of the most important graph skills.

BFS

Uses a queue and explores level by level. Useful for shortest paths in unweighted graphs.

DFS

Uses recursion or a stack and explores one path deeply before backtracking.

Visited Array

Tracks visited vertices so nodes are not processed repeatedly.

04 — VIDEO LEARNING

Before You Solve

Watch the concept lesson, then return to practice.

▶
FOUNDATION

Graph Basics

Vertices, edges and representation.

▶
CORE

Stack - DFS

Master graph traversal.

▶
INTERVIEW

Queue - BFS

Dijkstra and topological sorting.