◄ BACK_TO_INDEX.exe
[GRAPH] MODULE LOADED
BREADTH_FIRST
Explore all nodes at present depth before moving deeper. Guaranteed shortest path in unweighted graphs.
TIME_COMPLEXITY
O(V+E)
SPACE_COMPLEXITY
O(V)
DIFFICULTY
INTERMEDIATE
PROCESS: BREADTH_FIRST.exe■ COMPLETE
> initializing grid…
> step[001/000]
██ START██ GOAL██ FRONTIER██ CURRENT██ VISITED██ PATH██ WALL
strip below = FIFO queue (head-left, next to dequeue) · cell.g = BFS depth ring from START
CLOCK_SPEED
DECRYPTED_SOURCE.js● LIVE
// BFS.js — O(V + E) time complexity
// Finds the shortest path in an unweighted graph.
// graph is an adjacency list: { node: [neighbors] }.
function bfs(graph, start, goal) {
const queue = [start]; // FIFO frontier to explore
const visited = new Set([start]);
const parent = new Map(); // how we reached each node
while (queue.length > 0) {
// Dequeue the shallowest unexplored node
const node = queue.shift();
// Goal reached — walk parent links back to the start
if (node === goal) {
const path = [node];
let step = node;
while (parent.has(step)) {
step = parent.get(step);
path.unshift(step);
}
return path; // DECODED
}
// Enqueue every unseen neighbor, one depth level deeper
for (const next of graph[node]) {
if (!visited.has(next)) {
visited.add(next);
parent.set(next, node);
queue.push(next);
}
}
}
return null; // No path exists
}DECRYPTED_LOGIC.txt
01Start at the source node and mark it as visited
02Add the source to a FIFO queue holding the frontier
03Dequeue a node and enqueue all of its unvisited neighbors
04Record each neighbor's parent to reconstruct the path later
05Stop at the goal — the first path found is the shortest