-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
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
Greedy min vertex cover hacktoberfest #5241
Greedy min vertex cover hacktoberfest #5241
Conversation
graphs/greedy_min_vertex_cover.py
Outdated
while queue and not queue[0][0] == 0: | ||
# extract vertex with max rank from queue and add it to s | ||
argmax = heapq.heappop(queue)[1][0] | ||
S.add(argmax) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uppercase is reserved for constants in Python yet this line changes S
so S
is not a constant.
graphs/greedy_min_vertex_cover.py
Outdated
S = set() | ||
# queue used to store nodes and their rank | ||
queue = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move these definitions down to line 35 so that we do not define variables until we are actually ready to use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better variable names…
graphs/greedy_min_vertex_cover.py
Outdated
heapq.heappush(queue, [-1 * len(v), (k, v)]) | ||
|
||
# s = set of chosen vertices | ||
s = set() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s = set() | |
chosen_vertices = set() |
and make similar changes elsewhere,
* added complete graph generator function * added doctest, type hints, wikipedia explanation * added return type hint for function complete_graph * added descriptive name for the parameter: n * random graph generator with doctest and type hints * added Greedy min vertex algorithm * pre-commit hook(s) made changes * Delete complete_graph_generator.py * Delete random_graph_generator.py * fixed doctest * updated commit following highligths * fixed following pre-commit highlights * modified variables names
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.