Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make graph.add_edge run in O(1) instead of O(degree(V)) #2

Merged
merged 1 commit into from May 2, 2018

Conversation

dkorduban
Copy link

@dkorduban dkorduban commented Apr 10, 2018

Right now graph.add_edge runs in O(degree(V)) because node_neighbors is a list and v not in self.node_neighbors[u] runs in O(len(self.node_neighbors)). This leads to O(EV) creation time for dense graphs. Another worst case is a star — a graph where a single vertex is connected to each of other vertices, which will be constructed in O(V^2) having just O(V) edges & vertices.

This pull request fixes v not in self.node_neighbors[u] running time by making node_neighbors a set, which guarantees O(1) __contains__ check. neighbors still cast it to list for immutability & backward compatibility.

@coveralls
Copy link

coveralls commented Apr 10, 2018

Pull Request Test Coverage Report for Build 19

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 93.654%

Files with Coverage Reduction New Missed Lines %
core/pygraph/algorithms/minmax.py 3 95.24%
Totals Coverage Status
Change from base Build 17: -0.2%
Covered Lines: 1225
Relevant Lines: 1308

💛 - Coveralls

@goldragoon
Copy link

@agroszer
Why don't you review this pull request?
I think it's quite nice.

@agroszer
Copy link
Member

agroszer commented May 1, 2018

yeah, did not notice the PR...

@dkorduban would be nice to get coverage back

@dkorduban
Copy link
Author

The coverage issue is unrelated to the changes (the same happens in #1 ). I can fix it in a different pull request though.

@agroszer
Copy link
Member

agroszer commented May 2, 2018

had that feeling....

thank you

@agroszer agroszer merged commit d5760a1 into Shoobx:master May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants