Community

Ask A Question


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

anyone can help?

General • Asked 20 days ago by Rajarat Veshist

Gravatar Rajarat Veshist Commented on May 30, 2019:

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?

Gravatar Jake 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

Copyright © 2019 All rights reserved - AlgoDaily
Privacy | Terms