C++ Data Structures: Dijkstra's Algorithm

Поделиться
HTML-код
  • Опубликовано: 2 ноя 2024

Комментарии • 19

  • @LamNguyen-jp5vh
    @LamNguyen-jp5vh 2 года назад +1

    Thank you so much for your help! Thanks to this, I understand the dijkstra algo better

  • @bumate90
    @bumate90 4 года назад +6

    Great video, however I would use letters to represent the vertices(A, B, C...) to avoid confusion.
    Also you can increase the readability by representing a node like this: pair node.
    This way your graph would contain nodes instead of edges.

  • @pseudounknow5559
    @pseudounknow5559 3 года назад +2

    Just to be inline with your graphical representation since it's an undirected graph when adding an edge we have to add 2 links like that :
    void Graph::addEdge(int v1, int v2, int weight){
    adj[v1].push_back(make_pair(v2, weight));
    adj[v2].push_back(make_pair(v1, weight));
    }

  • @hosseinyah4247
    @hosseinyah4247 4 года назад +2

    Such great video bro, leaved a like.

  • @student2432
    @student2432 3 года назад

    the code is perfect but visual studio is showing "can not open or find the pdb file"
    what should i do ?
    please help

  • @kennytran8203
    @kennytran8203 3 года назад +1

    Hey, love the vid! Would you mind explaining how one could take your current implementation and potentially add a way to describe each path as it passes through the iteration? Instead of displaying the distance would it be possible to output the route?

    • @pseudounknow5559
      @pseudounknow5559 3 года назад

      You would have to use an array of size V to keep track for each node from which node we have come. You can then implement a function to print recursively the path.

  • @igorswies5913
    @igorswies5913 8 месяцев назад

    Shouldn't the set be sorting the pair according to the weight, not the vertex? Are you sure this works?

    • @karamany9870
      @karamany9870 6 месяцев назад

      the extract_set has weight as first and vertex as second. So it's sorted according to the weights.

  • @ASD9344
    @ASD9344 2 года назад

    Will this implementation work for unweighted graph by inserting all weights as "1" ?

    • @sirmonke8946
      @sirmonke8946 Год назад

      This comment is over 1 year old and there is a 99% chance you already got the answer, but yes, it would work. However, in an unweighted graph is would be more effective to use breadth-first search instead.

  • @DanielDuran-dy7wd
    @DanielDuran-dy7wd Год назад

    How can I print the path it took?

  • @usamaahmadsaleem4183
    @usamaahmadsaleem4183 2 года назад

    how can we also print the shortest path it takes and not only the cost...

  • @itsmejohnson0891
    @itsmejohnson0891 2 года назад

    Hi.. can we use this C++ code on codeblocks ?

    • @CoffeeBeforeArch
      @CoffeeBeforeArch  2 года назад

      I don't know what codeblocks is, but this is just C++ code (not platform specific). If codeblocks just uses a mainstream C++ compiler, I don't see why not.

  • @webgpu
    @webgpu 4 года назад

    It doesn't show the "Path" (vertices from origin to destiny) just the total distance.

    • @CoffeeBeforeArch
      @CoffeeBeforeArch  4 года назад

      Yep!

    • @zomy2k
      @zomy2k 3 года назад

      @@CoffeeBeforeArch How would you go about printing the paths?

    • @pseudounknow5559
      @pseudounknow5559 3 года назад +2

      @@zomy2k You would have to use an array of size V to keep track for each node from which node we have come. You can then implement a function to print recursively the path.