Skip to content

Commit 15f17c3

Browse files
committed
Breadth first traversal
1 parent c51193d commit 15f17c3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

13-Tree-Traversal-Algorithms/01-BFS.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ class BinarySearchTree {
3737
}
3838
}
3939

40+
/**
41+
* 1. Create a queue (this can be an array) and a variable to store the
42+
* values of nodes visited
43+
* 2. Place the root node in the queue
44+
* 3. Loop as long as there is anything in the queue
45+
* 4. Dequeue a node from the queue and push the value of the
46+
* node into the variable that stores the nodes
47+
* 5. If there is a left property on the node dequeued - add it to the queue
48+
* 6. If there is a right property on the node dequeued - add it to the queue
49+
* 7. Return the variable that stores the values
50+
*/
4051
breadthFirstSearch () {
4152
if (!this.root) {
4253
return -1;

0 commit comments

Comments
 (0)