Skip to content
RED SAGSkills
medium10 pts · first answer countsgraphsbfsperformance

A JavaScript BFS that gets slow

This BFS on a graph with 10^6 nodes is far slower than expected. What is the main cause?

const queue = [start]
while (queue.length) {
  const u = queue.shift()
  for (const v of adj[u]) if (!seen[v]) { seen[v] = true; queue.push(v) }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions