Is There A Route Between Two Nodes Graph Problem | letsbug
Find Route Between Two Nodes Graph Problem Hi everyone in this article we are going to see how to solve the problem of finding route between two nodes of a graph. Before we start let's make sure that you know a little bit about graphs data structure and how to traverse through a graph. code: const testG = { 'A' : [ 'B' , 'C' ], 'B' : [ 'D' , 'F' , 'E' ], 'C' : [ 'F' ], 'D' : [], 'E' : [ 'F' ], 'F' : [], 'G' : [] } const path = ( graph , start , end ) => { if ( start == end ) return true const queue = [ start ] const visited = {} visited[ start ] = true while (queue.length) { const node = queue. shift () const neighbors = graph [node] for ( let i = 0 ; i < neighbors.length; i ++ ) { if ( ! visited[neighbors[i]]) { if (neighb