1function dfs(graph, start) {
2 const adjacency = buildAdjacencyList(graph);
3 const visited = new Set();
4 const stack = [start];
5 const order = [];
6 while (stack.length > 0) {
7 const current = stack.pop();
8 if (visited.has(current)) continue;
9 visited.add(current);
10 order.push(current);
11 const neighbors = adjacency.get(current);
12 for (let i = neighbors.length - 1; i >= 0; i--) {
13 stack.push(neighbors[i]);
14 }
15 }
16 return order;
17}