From a7c5ce4b6d1c3843f0eacd325d8373ee945e08d6 Mon Sep 17 00:00:00 2001 From: Avinash Pandey Date: Thu, 18 Jul 2019 23:55:35 +0530 Subject: [PATCH 1/2] corrected typo in dijkstra_sparse.md --- src/graph/dijkstra_sparse.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph/dijkstra_sparse.md b/src/graph/dijkstra_sparse.md index 7896e514a..ef7dacda1 100644 --- a/src/graph/dijkstra_sparse.md +++ b/src/graph/dijkstra_sparse.md @@ -30,7 +30,7 @@ Then the complexity of Dijkstra's algorithm is $O(n \log m + m \log n) = O(m \lo C++ provides two such data structures: `set` and `priority_queue`. The first is based on red-black trees, and the second one on heaps. -Therefore `priority_queue` has a smaller constant hidden constant, but also has a drawback: +Therefore `priority_queue` has a smaller hidden constant, but also has a drawback: it doesn't support the operation of removing an element. Because of this we need to do a "workaround", that actually leads to a slightly worse factor $\log m$ instead of $\log n$ (although in terms of complexity they are identical). From c96a35382b2d27857b8f3d53ec7610b5bcb9155c Mon Sep 17 00:00:00 2001 From: Avinash Pandey Date: Tue, 30 Jul 2019 13:54:26 +0530 Subject: [PATCH 2/2] fixed two typos in mst_prim.md --- src/graph/mst_prim.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph/mst_prim.md b/src/graph/mst_prim.md index ed95b4fa4..e99bf6935 100644 --- a/src/graph/mst_prim.md +++ b/src/graph/mst_prim.md @@ -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.