General • Asked over 5 years ago by Rajarat Veshist
in https://algodaily.com/challenges/implement-a-graph, I don't get why
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?
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