You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3c83c4b
Browse filesBrowse the repository at this point in the historyBrowse files
D3128: Update Prim's algorithm to match current implementation
- Consolidate two prim() overloads into a single signature with defaulted
WF and CompareOp template parameters (seed moved to second parameter)
- Remove init_dist parameter; add explicit requires clause for
basic_edge_weight_function with plus<> combine
- Update mst.hpp and prim.hpp signatures accordingly
- algorithms.tex: resolve \phil note by documenting delegation to
dijkstra_shortest_paths; fix lstinputlisting line range (24-39);
correct Mandates type (vertex_property_map_value_t<Weight>); add
init_shortest_paths precondition; update Effects; add Throws section;
add Remarks for disconnected-graph usage"
Find the minimum weight spanning tree of a graph using Prim's algorithm.
1694
-
1695
-
\phil{Use general form of dijkstra's shortest path?}
1694
+
Delegates to \lstinline{dijkstra_shortest_paths} with a projecting combine function that uses the edge weight directly rather than accumulating path distance.
When omitted, the default is \lstinline{edge_value(g, uv)}.
1739
1742
\end{itemize}
1740
1743
\pnum\effects
1741
1744
\begin{itemize}
1742
1745
\item
1743
-
\lstinline{predecessor[v]} is the parent vertex of \lstinline{v} in a tree rooted at \lstinline{seed} and \lstinline{weight[v]} is the value of the edge between \lstinline{v} and \lstinline{predecessor[v]} in the tree. When \lstinline{compare} is \lstinline{<} and \lstinline{init_dist==+inf}, \lstinline{predecessor} represents a minimum weight spanning tree.
1746
+
\lstinline{predecessor[v]} is the parent vertex of \lstinline{v} in a tree rooted at \lstinline{seed}
1747
+
and \lstinline{weight[v]} is the value of the edge between \lstinline{v} and \lstinline{predecessor[v]}
1748
+
in the tree. \lstinline{predecessor[seed] == seed}.
1749
+
When \lstinline{compare} is \lstinline{<}, \lstinline{predecessor} represents a minimum weight spanning tree.
1744
1750
\item
1745
-
If \lstinline{predecessor} and \lstinline{weight} are not initialized by the user, and the graph is not fully connected, \lstinline{predecessor[v]} and \lstinline{weight[v]} will be undefined for vertices not in the same connected component as \lstinline{seed}.
1751
+
For vertices not reachable from \lstinline{seed}, \lstinline{predecessor[v]} and \lstinline{weight[v]}
1752
+
retain their initialized values (as set by \lstinline{init_shortest_paths}).
1746
1753
\end{itemize}
1747
1754
%\pnum\result
1748
1755
\pnum\returns The total weight of the minimum spanning tree rooted at \lstinline{seed}.
1749
-
%\pnum\throws
1756
+
\pnum\throws
1757
+
\begin{itemize}
1758
+
\item\lstinline{std::out_of_range} if \lstinline{seed} is not a valid vertex ID in \lstinline{g}.
1759
+
\item\lstinline{std::out_of_range} if \lstinline{predecessor} or \lstinline{weight} are undersized for the graph.
1760
+
\item\lstinline{std::out_of_range} if a negative edge weight is encountered (for signed weight types).
1761
+
\item\lstinline{std::logic_error} if an internal invariant violation is detected.
1762
+
\end{itemize}
1750
1763
\pnum\complexity
1751
1764
\begin{itemize}
1752
1765
\item\textbf{Time:} $\mathcal{O}(|E|\log{|V|})$.
1753
1766
\item\textbf{Space:} $\mathcal{O}(|V|)$ auxiliary --- priority queue and bookkeeping arrays.
1754
1767
\end{itemize}
1755
-
%\pnum\remarks
1768
+
\pnum\remarks Only produces a spanning tree for the connected component containing \lstinline{seed}.
1769
+
For disconnected graphs, call \lstinline{prim} once per component with a seed vertex from each component.
0 commit comments