C++ optimal graph representation for prims algorithm (without boost) -
i looking representation of graph prim's algorithm.
e.g. represent graph bfs
typedef std::unordered_map<int, std::queue<int> > gr; is elegant , concise, maps each vertex queue of neighbours.
for dijkstra it's little more complex (weights in representation)
typedef std::pair<int, double> to_weighted_edge; typedef std::unordered_map<int, std::vector<to_weighted_edge> > gr; - use of priority queue.
if similar structure follows in prim's algorithm however, source of each edge need stored , if graph represented like:
typedef std::pair < std::pair<int,int>, double> from_to_weighted_edge; typedef std::unordered_map<int, std::vector<from_to_weighted_edge> > gr; then there redundant info stored (the source/from vertex).
any suggestions optimal graph representation in c++ prim's algorithm welcome!
ps: 1 of course represent graph std::vector<from_to_weighted_edge> there wouldn't o(1) lookup of neighbors, common characteristic of common graph representations.
Comments
Post a Comment