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) }
}Discussion 0
Join free to post in the discussion.
Related questions
- Slow email during signupBackend Developer
- What EXPLAIN tells youBackend Developer
- Asking for only a few fieldsBackend Developer
- Building a long string in a loopBackend Developer
- Checking if any rows existBackend Developer
- Edges in a tree with n nodesBackend Developer
- Most nodes in a binary tree of height 3Backend Developer
- What inorder traversal of a BST givesBackend Developer