From 631e6f3c1c8d8303cf0afc2a7fe75a4b32321a19 Mon Sep 17 00:00:00 2001 From: Manav bhikadiya <65337643+manavbhikadiya@users.noreply.github.com> Date: Fri, 23 Oct 2020 21:03:00 +0530 Subject: [PATCH 1/2] Create BFS Using JS --- ClassicalAlgos/BFS_algorithm/BFS Using JS | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ClassicalAlgos/BFS_algorithm/BFS Using JS diff --git a/ClassicalAlgos/BFS_algorithm/BFS Using JS b/ClassicalAlgos/BFS_algorithm/BFS Using JS new file mode 100644 index 0000000..0b28ab2 --- /dev/null +++ b/ClassicalAlgos/BFS_algorithm/BFS Using JS @@ -0,0 +1,27 @@ +BFS(node) { + // Create a Queue and add our initial node in it + let q = new Queue(this.nodes.length); + let explored = new Set(); + q.enqueue(node); + + // Mark the first node as explored explored. + add(node); + + // We'll continue till our queue gets empty + while (!q.isEmpty()) { + let t = q.dequeue(); + + // Log every element that comes out of the Queue + console.log(t); + + // 1. In the edges object, we search for nodes this node is directly connected to. + // 2. We filter out the nodes that have already been explored. + // 3. Then we mark each unexplored node as explored and add it to the queue. + this.edges[t] + .filter(n => !explored.has(n)) + .forEach(n => { + explored.add(n); + q.enqueue(n); + }); + } +} From dc9353c85a88fd37b97809ab67f89297df838509 Mon Sep 17 00:00:00 2001 From: Pahulpreet Singh <54016648+codelixir@users.noreply.github.com> Date: Mon, 4 Oct 2021 20:39:08 +0530 Subject: [PATCH 2/2] Rename BFS Using JS to breadthFirstSearch.js --- .../BFS_algorithm/{BFS Using JS => breadthFirstSearch.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ClassicalAlgos/BFS_algorithm/{BFS Using JS => breadthFirstSearch.js} (100%) diff --git a/ClassicalAlgos/BFS_algorithm/BFS Using JS b/ClassicalAlgos/BFS_algorithm/breadthFirstSearch.js similarity index 100% rename from ClassicalAlgos/BFS_algorithm/BFS Using JS rename to ClassicalAlgos/BFS_algorithm/breadthFirstSearch.js