Dijkstra algorithm | Code implementation

Поділитися
Вставка
  • Опубліковано 25 сер 2024
  • This video explains the implementation with code for the dijkstra algorithm which is also known as the single source shortest path algorithm.In this video, I have first shown the steps for the algorithm and then i have analyzed what data structures are required to find the shortest path from the source node to every other node or vertex.I have taken the simple implementation for easier understanding using arrays.You can implement using SET or MAP as well.I have shown dry run for an example and at the end of the video, i have shown the code walk through and explanation.CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    ========================================================================
    Join this channel to get access to perks:
    / @techdose4u
    INSTAGRAM : / surya.pratap.k
    SUPPORT OUR WORK: / techdose
    LinkedIn: / surya-pratap-kahar-47b...
    WEBSITE: techdose.co.in/
    TELEGRAM Channel LINK: t.me/codewithT...
    TELEGRAM Group LINK: t.me/joinchat/...
    =======================================================================
    CODE LINK: gist.github.co...
    USEFUL VIDEOS:-
    Dijkstra algorithm: • Dijkstra algorithm | S...

КОМЕНТАРІ • 90

  • @PiyushKumarPorwal
    @PiyushKumarPorwal 4 роки тому +68

    Awesome explanation.. it would be better if u could show the implementation using priority queue and adj list

  • @princebhati6376
    @princebhati6376 3 роки тому +7

    this is the only video on youtube of Dijkstra algorithm which explains as well as implement the algorithm.
    Very well explained . Helpful for the many tier 3 college students.

  • @rachellee9906
    @rachellee9906 3 роки тому +12

    I like how you always say "I hope you are understanding this." I am understanding this :)

  • @manikantabandla3923
    @manikantabandla3923 4 роки тому +10

    Additional note to the video:
    SSSP in a directed acyclic graph can be found in O(V+E) by finding topological sort ordering of the graph.

  • @mayurkapadnis4265
    @mayurkapadnis4265 2 роки тому +3

    Excellent ! how neat and superb explaination it was with proper examples and dry run.

  • @kumarpriyansh4238
    @kumarpriyansh4238 3 роки тому +4

    Exactly what i was looking for. Thank you sir.

  • @chenghuilee6982
    @chenghuilee6982 4 роки тому +2

    Thank you so much for the video. It helps me to understand this algorithm better!

  • @rishabhgoyal8110
    @rishabhgoyal8110 3 роки тому +7

    God Bless you, man! So there is only 1 line of difference in code between PRIMS and Dijkstra!

  • @mayank_singh_43
    @mayank_singh_43 Рік тому

    I think it is best explanation on youtube on this topic, it is awsm

  • @UK-04.0
    @UK-04.0 4 місяці тому

    Helpful 🙂

  • @chinmoybhattacharya9561
    @chinmoybhattacharya9561 2 роки тому +2

    Thanks for creating this series of videos. Can you please add LLD and HLD playlist or point to some good resources for them.

  • @DhruvilPatel
    @DhruvilPatel 3 роки тому +2

    Simple and clear!

  • @anushrut5
    @anushrut5 4 роки тому +2

    just went to your website, feels good to know that you are a fellow shinobi

  • @ajitbombe5168
    @ajitbombe5168 3 роки тому +2

    Thanks...
    Simple and clear explanation.

  • @rishabhkumar8115
    @rishabhkumar8115 3 роки тому +2

    i appreciate your work..a very very thank you sir.

  • @aishikroychaudhury8656
    @aishikroychaudhury8656 3 роки тому +5

    Thanks so much for the video. Among other videos on youtube on Dijkstra's algorithm this was the best.
    Can you please answer if the algorithm works (without any modification) even if more than one unprocessed nodes are minimum cost at any iteration?

    • @techdose4u
      @techdose4u  3 роки тому +1

      Yes it does. You can choose any one.

  • @kunalsoni7681
    @kunalsoni7681 4 роки тому +1

    Wow 😊 beautiful video everything very clear in this video.. thanking you so much sir ❤️😍😇

  • @bhaveshvarma4313
    @bhaveshvarma4313 3 роки тому +3

    Good explanation, But I want to see how we can use heap(priority_queue) for optimization version because during updation of distance we can't update it directy in heap(priority_queue) . There is no decrease key operation available in priority queue.
    For this we have to define our own min_heap with some some changes. So if you have solution then please ans it so we can use priority_queue.

    • @techdose4u
      @techdose4u  3 роки тому

      Hmmm...I will show it in some problem

  • @theghostwhowalk
    @theghostwhowalk 4 роки тому +1

    As always! Spot on great explanation.

    • @techdose4u
      @techdose4u  4 роки тому +2

      Thanks :)

    • @theghostwhowalk
      @theghostwhowalk 4 роки тому

      @@techdose4u One Q.. Are you planning to cover Bellman-Ford too? for -ve weight cycles..

    • @harshgupta9761
      @harshgupta9761 3 роки тому

      @@techdose4u can you explain dijkstra by adjacency list and min heap

  • @ayyappareddy4461
    @ayyappareddy4461 3 роки тому +1

    Thank you sirrrrr superrr explaination

  • @MayankLC93
    @MayankLC93 3 роки тому +1

    THANK YOU !!!!!!!!!!!

  • @v.sreesairam9488
    @v.sreesairam9488 3 роки тому +1

    understood :) thank you bhaiya

  • @PriyankaSharma02499
    @PriyankaSharma02499 3 роки тому +1

    Very nice explanation 🙂

  • @AltafHussain-on2oe
    @AltafHussain-on2oe 3 роки тому +1

    Thank you Sir 💖

  • @adarshkaran6611
    @adarshkaran6611 Рік тому

    thank you sir!

  • @amitkumargupta6722
    @amitkumargupta6722 3 роки тому +1

    just awesome...

  • @arpanbanejee5143
    @arpanbanejee5143 2 роки тому +2

    Very nice explanation! Thanks! one small doubt, using the adjacency list how will it improve the time complexity?

    • @techdose4u
      @techdose4u  2 роки тому +1

      If the graph is sparse use list otherwise array.

  • @ApoorvaRajBhadani
    @ApoorvaRajBhadani 3 роки тому +2

    Please also include code for Priority Queue implementation. Why create half videos.
    Anyways the explanation is excellent.

    • @techdose4u
      @techdose4u  3 роки тому +1

      It's easy to replace the priority queue code :)

  • @ap331
    @ap331 4 роки тому +2

    Sir regarding every algo implementation....it should be practised on daily basis ?

    • @techdose4u
      @techdose4u  4 роки тому

      You should practice atleast 1 problem daily from the topic you feel uncomfortable with.

  • @akhilsharma1778
    @akhilsharma1778 3 роки тому +2

    I have seen another way of doing it using heap which i think is more time efficient but more complicated, which one should i try because i find the heap one a little difficult to understand?

    • @techdose4u
      @techdose4u  3 роки тому +1

      Heap is also easy. I have explained the simplest approach which everyone can understand but you can use priority queue STL/library to implement heap :)

  • @priyachaturvedi9381
    @priyachaturvedi9381 3 роки тому +1

    Excellent explanation! Could you please make a video on 0-1 BFS as well?

    • @techdose4u
      @techdose4u  3 роки тому +1

      Sure. But it will take time since I want to complete the course 😅

    • @priyachaturvedi9381
      @priyachaturvedi9381 3 роки тому

      @@techdose4u Surely, Sir! Please take your time. 😄

  • @nikoangiuli
    @nikoangiuli 3 роки тому +1

    Thanks is a precious explanation. Can I ask you if Dijkstra's algorithm is the one used in the Amazon warehouses to define the pick paths for the pickers?

    • @adithyav9283
      @adithyav9283 3 роки тому

      yes

    • @nikoangiuli
      @nikoangiuli 3 роки тому

      @@adithyav9283 thanks can you suggest me some readings about it?

  • @JSDev776
    @JSDev776 3 роки тому

    can we just take a queue and only push to it if the value of vertex is updated, we can skip the visited array and looping through all vertices thing right?

  • @priyanshugupta521
    @priyanshugupta521 3 роки тому

    What kind of traversal is better for this algorithm ? Dfs or bfs

  • @KshitijJain
    @KshitijJain 4 роки тому

    Hey Buddy, very nice explanation. Can I know what do you use to write and record?

  • @ayushgarg5929
    @ayushgarg5929 4 роки тому +1

    Sir please make a video on Josephus Problem

    • @techdose4u
      @techdose4u  4 роки тому +1

      Sure bro. I will make it but after finishing current series.

  • @mananmehta2320
    @mananmehta2320 2 роки тому

    13:20 Is this process necessary? To go and check which nodes haven't been visited...?

  • @funWithAnkit
    @funWithAnkit 2 роки тому

    Why to use Dijkstra's algorithm when the BFS using a queue can be used to find minimum distance of nodes from a given source in O(V + E) time complexity.

  • @ankitjangir01
    @ankitjangir01 2 роки тому

    Isn't is same as Prim's algo ?

  • @divaynagar1929
    @divaynagar1929 3 роки тому

    will this code give wrong answers for negative weight edges

  • @itsmejohnson5931
    @itsmejohnson5931 2 роки тому

    Can you execute the code in code blocks and show it?

  • @moulikasunesh2834
    @moulikasunesh2834 3 роки тому +1

    Here the adjacency matrix is created and this doesn't change with the variables. looks like this is hardcoded

    • @moulikasunesh2834
      @moulikasunesh2834 3 роки тому

      And if you have to create this matrix dynamically you should be going through the given data i guess

    • @techdose4u
      @techdose4u  3 роки тому +1

      Adjacency matrix is hardcoded but you can always create taking inputs.

  • @dayanandraut5660
    @dayanandraut5660 3 роки тому

    can anyone post the link for dijkstra's algo implemented using minheap in java?

  • @ghoshdipan
    @ghoshdipan 3 роки тому +1

    sir can you please show the java code too

    • @techdose4u
      @techdose4u  3 роки тому +2

      I am providing java codes now. But I did not provide back when I made these videos. I will add them.

  • @louis1458
    @louis1458 2 роки тому

    7:46

  • @supernova7870
    @supernova7870 3 роки тому +1

    Sir, why are you always taking minimum distance vertex from VALUE Array , what is the logic behind that ??

    • @techdose4u
      @techdose4u  3 роки тому +1

      Because we want to make a greedy decision to select minimum cost path from all adjacent edges.

  • @pavanioruganti3526
    @pavanioruganti3526 3 роки тому

    How to get distance between neighbours and get neighboursnames

  • @kainaatmakhani6550
    @kainaatmakhani6550 2 роки тому

    sir plzz ap yeh dijkstras algorithm ke notes aur coding bhej dijey takhe mein apne paas download kar sakhun plzz?

  • @amc1140
    @amc1140 2 роки тому +1

    Relax?

  • @ridimamittal4064
    @ridimamittal4064 2 роки тому

    content is good but voice is tooo low