NeverFlight / CS435-Project2-Part2

0 stars 0 forks source link

Comment 5 #1

Open ak2253 opened 4 years ago

ak2253 commented 4 years ago

Try using a HashMap<node,int> instead of an array of indegrees to track nodes and their current indegrees in the method: https://github.com/NeverFlight/CS435-Project2-Part2/blob/d2214e6197e00763e03a18aacb510f210ff396cb/src/com/cs435/part2/Main.java#L58-L88 This way the search time is just as fast and it is not dependent on the values of the graph in case a graph contains a node with a value larger than the number of nodes in graph.

NeverFlight commented 4 years ago

That's a good point when we might have some nodes with the duplicate value, or as you mentioned, some large value node will cause the index out of bounds in the array. But on this project's graph, the nodes' value is strictly on the range from 0 to n, so from my perspective, there is no need to use the HashMap here. (Map usually is much expensive than just an array if they have the same size).