Practice Discrete Math

Algorithms / Graph Traversal

Least You Need to Know: BFS, DFS, and Connected Components

**Breadth-first search** explores layer by layer, while **depth-first search** follows one path deeply before backtracking. Both are core graph tools, and both can be used to discover reachability and connected components.

جو کم از کم جاننا ضروری ہے

اہم علامتیں

BFS breadth-first search
DFS depth-first search
component maximal connected piece of an undirected graph

مختصر حل شدہ مثال

  • Starting from a source vertex, BFS first visits all neighbors at distance 1.
  • Then it visits vertices at distance 2, then distance 3, and so on.
  • That is why BFS gives shortest paths in unweighted graphs.

عام غلطیاں

اس قسم کے سوال کو کیسے پہچانیں

Next recommended lesson

Continue through this topic with Least You Need to Know: Greedy Choice, Exchange Arguments, and Local Decisions.

Least You Need to Know: Greedy Choice, Exchange Arguments, and Local Decisions

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

مشق شروع کریں