Working with Graphs & Trees
What tree traversal order does this implementation produce?
function dfs(root) {
if (!root) return [];
const result = [];
const stack = [root];
while (stack.length) {
const current = stack.pop();
result.push(current.value);
if (current.right) stack.push(current.right);
if (current.left) stack.push(current.left);
}
return result;
}