Graphs: BFS and DFS
Model connections, then explore them level by level or path by path.
A graph is a set of nodes joined by edges. Store it as a dictionary from each node to its neighbours, and track visited nodes so you do not loop forever.
Expected output
['A', 'B', 'C', 'D']
BFS uses a queue and finds shortest paths when every edge counts the same. DFS uses recursion or a stack and suits questions about connected parts and cycles.