8000 Fixed two typos in mst_prim.md by mrpandey · Pull Request #448 · cp-algorithms/cp-algorithms · GitHub
[go: up one dir, main page]

Skip to content

Fixed two typos in mst_prim.md #448

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

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/graph/mst_prim.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ If we search the edge by iterating over all possible edges, then it takes $O(m)$
The total complexity will be $O(n m)$.
In the worst case this is $O(n^3)$, really slow.

This algorithm can be improves if we only look at one edge from each already selected vertex.
This algorithm can be improved if we only look at one edge from each already selected vertex.
For example we can sort the edges from each vertex in ascending order of their weights, and store a pointer to the first valid edge (i.e. an edge that goes to an non-selected vertex).
Then after finding and selecting the minimal edge, we update the pointers.
This give a complexity of $O(n^2 + m)$, and for sorting the edges an additional $O(m \log n)$, which gives the complexity $O(n^2 \log n) in the worst case$.
This give a complexity of $O(n^2 + m)$, and for sorting the edges an additional $O(m \log n)$, which gives the complexity $O(n^2 \log n)$ in the worst case.

Below we consider two slightly different algorithms, one for dense and one for sparse graphs, both with a better complexity.

Expand Down
0