Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

anyone can help?

General • Asked over 5 years ago by Rajarat Veshist

Rajarat Veshist Commented on May 30, 2019:

in https://algodaily.com/challenges/implement-a-graph, I don't get why

SNIPPET
addEdge(src, dest) {
  this.adjacencyList.get(src).push(dest);
  this.adjacencyList.get(dest).push(src);
  // push to both adjacency lists   
}

we need to push to both? isn't edge for both?

Jake from AlgoDaily Commented on May 31, 2019:

Hey Rajarat,

You need to push to both because it's an undirected graph-- the edge will always be bidirectional. If this were directed, it would point in one direction.

More reading at http://faculty.cs.niu.edu/~freedman/340/340notes/340graph.htm