🌑 THE DESCENT OF THE SEEKER — A Tale of DFS with a Stack
“Some cities don’t breathe. They **hide.
And only those who dive deep — patiently, ruthlessly — ever uncover their truth.”
— From “Journeys Beyond the Gates”, by Vaal of the Depths
🕯️ Prologue: Into the Shadowed City
The city of Karnath wasn’t like others.
It didn’t awaken to soft breath like Netra did.
Its stories weren’t on rooftops and open courtyards —
but buried. In tunnels, basements, in vaults locked deep.
You couldn’t wait for the city to show itself.
You had to dive.
So came the Seekers — a guild of quiet minds and steady hands.
They didn’t fan out like ripples.
They dove into one alley, then deeper, then deeper still…
Until there was no further to go.
Then — and only then — they’d backtrack.
They wielded no horn, only a single tool:
The Stack of Descent.
đź§± The Codex of Descent
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
The Seekers packed little:
- A map of secrets — where each corridor connects.
- A stack — the instrument of deep dives.
- A visited ledger — to avoid endless wandering.
📜 The City Blueprint
class Graph {
int V;
vector<vector<int>> adj;
public:
Graph(int V) : V(V) {
adj.resize(V);
}
void addEdge(int u, int v) {
adj[u].push_back(v);
adj[v].push_back(u);
}
The walls of Karnath were set.
With each addEdge(u, v)
, a hidden passage was etched between chambers u
and v
.
These weren’t streets.
They were choices, and each one had consequences.
🕳️ The Descent Begins — DFS with a Stack
void dfs(int start) {
vector<bool> visited(V, false);
stack<int> st;
st.push(start);
They began with a single step:
“Pick one gate. Don’t ask questions. Just go.”
Node start
was chosen — the first room of descent.
The Seeker stood at its mouth. He’d return to it later, perhaps. But first: in.
He pushed the room onto the stack — the path yet to be explored.
🔦 Into the Dark, One Room at a Time
cout << "DFS Traversal: ";
while (!st.empty()) {
int u = st.top(); st.pop();
if (!visited[u]) {
visited[u] = true;
cout << u << " ";
The Seeker pulled the room from the stack — not the oldest, but the most recent.
This was not a breath. It was a plunge.
If the room was already marked, he moved on.
But if it wasn’t…
He lit a lantern, etched its number in the Seeker’s Journal, and marked it as visited.
Another layer of the city had been claimed.
🧠Marking Next Steps — Deeper Still
for (int v : adj[u]) {
if (!visited[v]) {
st.push(v);
}
}
}
}
cout << "\n";
}
};
After exploring room u
, the Seeker didn’t fan out to all neighbors immediately.
He merely stacked them — to explore them later, and only one at a time.
He didn’t care about exploring all directions at once.
He was obsessed with depth.
Every neighbor that hadn’t been seen was a clue —
a whisper of something hidden further in.
He’d come back for them… in reverse.
Because a stack is Last In, First Out.
He’d chase the last path he discovered, as if fate was daring him deeper.
🔦 A Seeker's Journey — An Example
int main() {
Graph g(7);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 3);
g.addEdge(1, 4);
g.addEdge(2, 5);
g.addEdge(5, 6);
g.dfs(0);
}
In the maze of Karnath:
- From room 0, the Seeker dove into 2
- From 2 into 5
- From 5 into 6
Only when 6 was exhausted did he retreat — climbing back to 5, then to 2, then back to 0,
only to explore the other branch — into 1, then 3, then 4…
The traversal recorded:
DFS Traversal: 0 2 5 6 1 4 3
The order might vary, but the soul of it remains:
→ Dive until you can't.
→ Then retreat.
→ Then dive again.
đź§ The Wisdom of the Depth-Diver
-
stack<int> st
— the trail of your descent -
visited[]
— the only thing saving you from walking in circles -
dfs(start)
— the descent spell itself - No recursion. No help. Just memory, silence, and will.
DFS with a stack doesn’t float or ripple like BFS.
It hunts, and dives, and chases mysteries
deeper and deeper until it hits stone.
It is the Seeker’s Way,
and Karnath remembers.
“If the city breathes with BFS,
then it dreams with DFS.
And in dreams —
only those who dare to fall find the truth.”
Top comments (0)