[Verse 1]
Graph before me like a tangled maze of nodes
Each vertex holding secrets, down unexplored roads
Stack in hand, I choose my weapon for the quest
Dive deep first, leave breadcrumbs, forget the rest
Mark my starting point as visited and true
Push it down, the stack awaits what I pursue
Pop the top, examine neighbors one by one
If unvisited, the plunge has just begun
[Chorus]
DFS goes deep, deep, deeper than the rest
Stack Last In First Out puts recursion to the test
Mark visited, push neighbors, pop and repeat
Deep First Search, concrete beat, make the algorithm complete
Go deep, deep, deeper, chase each branching thread
Stack or recursive calls, either way we're led
[Verse 2]
Recursive elegance or iterative might
Both approaches cut through data structure night
Function calls itself on every neighbor found
Call stack growing as we spiral underground
Base case hits when dead ends block the way
Backtrack automatic, let recursion replay
Time complexity O of V plus E combined
Space complexity haunts with stack frames aligned
[Chorus]
DFS goes deep, deep, deeper than the rest
Stack Last In First Out puts recursion to the test
Mark visited, push neighbors, pop and repeat
Deep First Search, concrete beat, make the algorithm complete
Go deep, deep, deeper, chase each branching thread
Stack or recursive calls, either way we're led
[Verse 3]
Topological sorting when the graph's directed
Strongly connected components get detected
Cycle detection in a maze of dependencies
DFS reveals the hidden frequencies
Forest grows from disconnected pieces scattered
Run from each unvisited, nothing else matters
Applications bloom in scheduling and planning
Graph traversal mastery, understanding expanding
[Bridge]
When breadth goes wide, depth penetrates the core
Stack discipline versus queue's spreading spore
Choose your weapon based on what you seek to find
Deep exploration or the broad searching mind
[Outro]
Visited array, the memory of our trace
Adjacency lists guide us place to place
DFS conquered, algorithm internalized
Deep First Search, specialized, optimized