Dijkstra's Algorithm Single Source Shortest Path Graph Algorithm

  Рет қаралды 395,407

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер: 173
@niteshgyanani9947
@niteshgyanani9947 3 жыл бұрын
Aapse acha teacher aaj tak nhi dekha...itna ache se kisi ne nhi smjhaya ye sab...you are really good ❤️❤️
@sidhantakumarpattnaik2962
@sidhantakumarpattnaik2962 9 жыл бұрын
You are awesome .I viewed almost all videos and its clear my concept , which not being cleared by seeing other videos . Keep posting new videos and this will help us .
@kshitijarunabh968
@kshitijarunabh968 7 жыл бұрын
bro do these videos help in company placement.does it helped you...
@RahulGvpta
@RahulGvpta 3 жыл бұрын
Obviously!! He works at Apple. Hope this answers your question.
@sunnykeshshandilya1156
@sunnykeshshandilya1156 8 жыл бұрын
Awesome man. You make any algorithms so easy and teaches 3hr things in 15 mins and concept given is very solid. One small thing missed in video.. explanation for time complexity O(E log V)
@Dreamazium
@Dreamazium 7 жыл бұрын
You do seem to be able to explain things much better than others. Uni is rubbish at explaining things while you have given me at least given me a chance of understanding it. It seems much simpler now you have explained it. Thank you.
@DentrifixoRam88
@DentrifixoRam88 6 жыл бұрын
He's awesome
@BackToBackSWE
@BackToBackSWE 6 жыл бұрын
Loved the video. This was a fundamental concept in our Object Oriented 2 class.
@adarshsharmanit356
@adarshsharmanit356 4 жыл бұрын
He is from my college , Working in Apple
@harjos78
@harjos78 6 жыл бұрын
One of the best and simplest videos for understandng dijkastra's algo.. Hats off Tushar... Great work!
@DentrifixoRam88
@DentrifixoRam88 6 жыл бұрын
I just looked for a video from you about Dijkstra. You're the best teacher I've found in KZbin.
@wth5715
@wth5715 8 жыл бұрын
I`m student in korea. Your good explanation Thanks Tushar Roy~
@tusharroy2525
@tusharroy2525 8 жыл бұрын
welcome
@adarshsharmanit356
@adarshsharmanit356 4 жыл бұрын
@@tusharroy2525 Hello MNNITian SIR !!
@edmondshek7072
@edmondshek7072 6 жыл бұрын
Roy's doing things for global audience, I benefit a lot from his videos as a Chinese student.
@CabCallawayMusic
@CabCallawayMusic 6 жыл бұрын
The other videos explaining the algorithm aren't bad, but this is the best one when trying to understand the pseudo code and data structures - thanks!
@blazingsniper1239
@blazingsniper1239 4 жыл бұрын
you helped me in bachelors and need you again in masters god bless you
@w9ahmed
@w9ahmed 8 жыл бұрын
Dude, these lessons are really simple and easy to grasp. Thanks a lot, definitely helping me in my quiz tomorrow!! KEEP IT UP! :)
@jonathanbain14
@jonathanbain14 8 жыл бұрын
absolutely fantastic explanation! Thank you so much for going through even the most obvious bits as now I have a -rough- idea of how i'm actually going to implement part of my algorithmics C assignment! cheers.
@ayush47662
@ayush47662 8 жыл бұрын
Very nicely explained, especially the complexity part. I could not understand that from other sources. thank you!!
@AvaisAhmad
@AvaisAhmad 9 жыл бұрын
I really liked your videos. Can you please upload videos on some of following topics? ->asymtotic complexity -> n queen problem ->travelling salesman problem ->karp-rabin ->strassen matrix multiplication ->randomized algorithms las vegas and monte Carlo ->Amortized analysis ->LC Branch and Bound ->FIFO Branch and Bound ->Multistage Graph ->Flow Shop Scheduling ->binomial heap ->fibbonaci heap
@AvaisAhmad
@AvaisAhmad 9 жыл бұрын
+Tushar Roy thanks
@reehji
@reehji 8 жыл бұрын
dude, your vids are like gold to self-learning coders :) Really appreciate the efforts!
@mesodylaughter9327
@mesodylaughter9327 11 күн бұрын
Thought I will never get an idea till I found this channel 😂
@rafamassa
@rafamassa 9 жыл бұрын
First Dijkstra's explanation ever that allowed me to visualize the data transformations!
@anamigator
@anamigator 6 жыл бұрын
If you are still guessing, why the O(E log (v)) complexity, here is an explanation. You visit each edge in this graph at-least once (without which you cannot reach all the vertices). That would be O(E). However, at each edge, you are looking at the priority queue (heap) and doing an extractMin() operation which takes log(n) time in general, for n elements in the heap. Since in the worst case, you will have as many as V elements in the heap, each edge traversal means, a O(log V) time to extractMin from the priority queue(heap). So E times log(v).
@maksimmartianov5189
@maksimmartianov5189 4 жыл бұрын
What about construction of the heap? Isn't it O(v) ?
@amurto630
@amurto630 4 жыл бұрын
Isnt extract min operation O(1) while insertion is O(logV)
@Bdixit
@Bdixit 3 жыл бұрын
@@maksimmartianov5189 The highest degree term is considered in time complexity and hence E will be always >= V, therefore we can say total time complexity as O(E log (v))
@Bdixit
@Bdixit 3 жыл бұрын
@@amurto630 Extract-Min in heap is an operation in which we extract root i.e. min element and then replace it with last level rightmost element and then heapify, so the total time to do this will be O(log V).
@sureshdavid4404
@sureshdavid4404 9 жыл бұрын
Thanks for the video . I am new for learning in youtube . i felt lot of difference to learn from videos . i have seen many videos recently , yours is fantastic . with code base .
@crazywasy
@crazywasy 9 жыл бұрын
Tushar, thank you so much for your effort. It helps me to understand many things and succesfully take my exams. Thank you!
@GabrielaSwanson
@GabrielaSwanson 7 жыл бұрын
Great video! Thank you so much for your clear explanations and demonstrations.
@kaushalgala
@kaushalgala 6 жыл бұрын
Watched many of your videos, and most of these videos are well explained - good for freshers to computer science, as well as those who want to dust up academics in preparation for new opportunities. Want to commend you on all your great efforts.
@mythbuster533
@mythbuster533 7 жыл бұрын
Your videos are so much better and informative than Siraj ravla's!! Great job!!
@arthamsreenivas8858
@arthamsreenivas8858 5 жыл бұрын
Great Video and this channel is my bible for programming questions.
@mibo747
@mibo747 3 жыл бұрын
Thanks God man. you saved me from quitting learning...
@elegancebliss3618
@elegancebliss3618 5 жыл бұрын
HEY I want to thank you, I will forever be grateful if I pass my exams thanks to you! keep it up man!
@sagnik3012
@sagnik3012 4 жыл бұрын
Well, did you pass? :P
@elegancebliss3618
@elegancebliss3618 4 жыл бұрын
@@sagnik3012 yeah I did xd
@gowtham2775
@gowtham2775 6 жыл бұрын
Thanks man, for keeping it simple and clear unlike others
@jaimu30
@jaimu30 8 жыл бұрын
Awesome explanation man, you saved me for my final tomorrow :).
@oknows2
@oknows2 9 жыл бұрын
Excellent, clear explanation. Well-done.
@technoblast4282
@technoblast4282 8 жыл бұрын
your lectures were very helpful me....thanks Tushar for your wonderful videos
@vishul1000
@vishul1000 5 жыл бұрын
One correction at 11:53 we apply extract min V times and decrease key E times. And not both E times.
@100vivasvan
@100vivasvan 7 жыл бұрын
You are AWESOME! Thank you so much God bless you! awesome video! Helped me a lot in understanding this i had struggled a lot with this algo.
@jiakaiguo9495
@jiakaiguo9495 9 жыл бұрын
Great Explanation! Thank you so much Tushar!
@kunalkathpal7167
@kunalkathpal7167 9 жыл бұрын
buddy you are soo good AND you explain very well!!
@priyankakunwar8685
@priyankakunwar8685 4 жыл бұрын
U r not Tushar u r an ultimate solution
@kiooobotu
@kiooobotu 9 жыл бұрын
I like your videos a lot. This explanation of Dijkstra algorithm is one of the best I've ever seen. Have you ever thinking about make a video of A* algorithm or another search algorithm that uses heuristics? Keep making videos :) Thanks.
@kiooobotu
@kiooobotu 9 жыл бұрын
Really? I didn't see it. Thanks :)
@shubhamsharma0420
@shubhamsharma0420 8 жыл бұрын
Man, i am speechless. Awesome video.
@cashflow9156
@cashflow9156 9 жыл бұрын
Thanks for doing a video on Dijkstra!
@mohityadav8383
@mohityadav8383 7 жыл бұрын
The legend in explaining and teaching :)
@khaledsaleh4238
@khaledsaleh4238 7 жыл бұрын
Thank you very much, Tushar. Really helpful tips and efficient code.
@bhatwahid5107
@bhatwahid5107 8 жыл бұрын
Wish I could have viewed these videos earlier I could have been much better in algorithims .Thankyou sir !
@AdvaitPatel007
@AdvaitPatel007 8 жыл бұрын
Great videos buddy. Awesome job!
@rrh2400
@rrh2400 6 жыл бұрын
So helpful and clear. Thank you so much.
@SALMUZ
@SALMUZ 8 жыл бұрын
Amazing explanation man .. that will really help me into my project. greetings ..
@madhukiranattivilli2321
@madhukiranattivilli2321 3 жыл бұрын
Should use D-ary heap instead of Binary heap w/ Dijkstra's algo. D is tree order (i.e. max # of children of any node). D=log2(V) (D=E/V is another way, but log2(V) gives better performance). removemin and decrease are the 2 prominent OPs among which decrease is more frequent (O(E), removemin at O(V)). decrease causes swim whereas removemin causes sink. swim causes comparison b/w a node with it's parent, all the way till the root if required, whereas sink causes getting the smallest among all children and comparing that with the node, all the way till final level if required. So swim performs better with D-ary heap whereas sink performs better with binary heap. But since swims are more frequent than sinks, D-ary heap has to be used with D=log2(V) to strike a balance in the performance of sinks and swims. sink and swim run in O(log2(V)) time with binary heap. With D-ary heap they run in O(log(V)) time =~ O(log(V)) time
@alifiyahh6387
@alifiyahh6387 5 жыл бұрын
such a clear explanation thank you!!
@Joyddep
@Joyddep 5 жыл бұрын
Really good explanation!
@kaushalgupta7891
@kaushalgupta7891 8 жыл бұрын
awesome man, u r really helpful
@bored78612
@bored78612 8 жыл бұрын
Very nice explanation. Thank you.
@Matrix_Decoded
@Matrix_Decoded 9 жыл бұрын
thankyou sooo much !!! an IP university student
@svssukesh1170
@svssukesh1170 6 жыл бұрын
Clear explenation....verry helpful
@saini85193
@saini85193 9 жыл бұрын
Perfect as always..!
@HarshaSuranjith
@HarshaSuranjith 8 жыл бұрын
Thanks, this helped me a lot !
@kevinmarti2099
@kevinmarti2099 7 жыл бұрын
Your videos are top!
@amitgp2007
@amitgp2007 8 жыл бұрын
u r excellent..Its helping ..
@adarshchaudhary5362
@adarshchaudhary5362 8 жыл бұрын
I hardly comment on videos. But man you are awesome. BTW are you IITian?
@omkarpanhalkar6837
@omkarpanhalkar6837 8 жыл бұрын
he is an Apple Engineer
@miguelangelpomahuayta253
@miguelangelpomahuayta253 6 жыл бұрын
Genius you helped me find the error
@jdragon8184
@jdragon8184 4 жыл бұрын
at first i was using dfs to reach all vertex and update but that method was flawed thnx to him i used bfs and got correct ans for each test case
@ganapatibiswas5858
@ganapatibiswas5858 4 жыл бұрын
Why the playlist is not in organized manner ? But the video was awesome :)
@MrDivad006
@MrDivad006 8 жыл бұрын
Excellent explanation!
@madatbrahma4389
@madatbrahma4389 8 жыл бұрын
Hi Tushar, Your explanations on the algorithms are brilliant. Have a doubt on extracting minimum value from the map. Why are we extracting minimum value from the map? Picking up any random value/max value from the map will give the same final result. Since for every vertex, we are comparing already found distance and new distance. Only observation I found that using minimum one form the map reduces number of comparisons. Can you please put your thoughts on selecting the minimum one from the map instead of any other value?
@michaelwaters1358
@michaelwaters1358 8 жыл бұрын
+madat brahma I think we extract the minimum because the distance cannot be updated once it has been removed. What I mean is, if you look at his example on the board, D is the last element to get extracted. If it was the second (after the source which is A), then it would be extracted with the distance 9. This is then used to compare other paths with and therefore should not be updated (as any path that relies on D would then have to have their distance updated as well). Extracting the minimum guarantees that all the data in the distance map is the smallest value possible for that vertex. To explain this better, lets say there is a graph of 4 elements ABCD, connected like a square. A is the source, so it is extracted first. It is connected to B and D. Let's say that the edges for AB is 2, BC is 3, CD is 2, and AD is 8. If you extract at random, D could be removed next, making D have a distance set to 8. Then when you eventually extract C, it would be seen that D's distance could be updated to 7, which is less than 8. This isn't a problem at first. But if there were 5 elements, with a node E connected to D but no others, then this would require you to update the distance of E as well, because it is reliant on D's distance. This would introduce another loop of O(v) time every time you update a distance (since you have to check all the nodes that are reliant on that nodes distance). This increases the time complexity since it would occur inside the for loops that are already O(E lg (v)) (I think that's the time complexity, I could be remembering that wrong). By extracting the minimum, it guarantees that anything dependent on that node will not have to have its distance updated once it is extracted.
@DurgeshKumawatdk
@DurgeshKumawatdk 9 жыл бұрын
excellent....good explanation
@mayursandbhor8824
@mayursandbhor8824 8 жыл бұрын
videos are awesome . After doing the concept part can you please add complexity of each algorithm?
@mayursandbhor8824
@mayursandbhor8824 8 жыл бұрын
Complexity for travelling salesman problem 0/1 Knapsack optimal BST N * queen problems
@georgikoyrushki7825
@georgikoyrushki7825 8 жыл бұрын
Hi Tushar, Thank you for your excellent explanation- just as always. I have only one question- how is the space complexity O(E + V) when in all three data structures we only store at most V elements where V is the number of vertices in the graph? This is the only thing I don't understand. Thank you :)
@zejkeje
@zejkeje 7 жыл бұрын
the graph you are searching contains a list of vertices and their edges so I guess the space complexity is just the size of the input data in this case because the other structures are smaller
@Khudsaybaat
@Khudsaybaat 6 жыл бұрын
Hi
@kishoresahoo9354
@kishoresahoo9354 9 жыл бұрын
Hi Tushar, I watched many of your algo videos... Many of the concepts are clear now. First of all A BIG THANKS for your videos. In programming part in many videos, you have used Map, LinkedList, Queue and so on. Can you post some videos where programming is done only using Arrays and Objects? Arrays like any array of objects rather using predefined java classes. e.g. int[], Object[], etc. As i need to appear few exams where we can not import any predefined class apart from java.util.Scanner;
@rajmehta017
@rajmehta017 7 жыл бұрын
Hey Tushar, we're not just extracting the minimum value but we're also removing it from the map + heap. However, in your video about Prim's, you haven't explained how to remove the minimum value from the data structure. Obviously, if we remove the top element (which is the minimum), the position of all the other elements change and in such a case, how do we update the map (which contains the positions)?
@rajmehta017
@rajmehta017 7 жыл бұрын
Here's what I did: after removing the element whose index is 0 in the heap (since it would be the lowest value), I am decrementing the index of every other element in the hash map by 1. So the element whose value in the hash map was previously 1, now becomes 0. 2 becomes 1 and so on, which is also what happens to the heap array naturally after we pop out the element at the 0th position. Thank you so much Tushar, my code is working fine, this is the first time I've implemented Dijkstra's algorithm, feels good :) Even though my code is working fine, someone do let me know whether what I did was the correct thing to do. It may be possible that my code breaks in some special cases.
@VikramMeena1
@VikramMeena1 8 жыл бұрын
Nice Video... Please, Put captions above progress bar....
@Ronakrktanna
@Ronakrktanna 8 жыл бұрын
Hi, Can you make a video explaining the code from the Graph, Vertex and Edge classes that you have in the link you've provided? To be specific, I want to know the significance of the overridden functions that you've written and why they're coded that way. Thanks!
@asifbilla4924
@asifbilla4924 7 жыл бұрын
Great explanation..
@pravinmed
@pravinmed 5 жыл бұрын
Why do we need a Min heap ? Can we not store in the Queue instead and have a visited array to keep track of which nodes are visited prior. Although you can modify the distance but do not put back to the queue if it is already visited.
@ashleycole3054
@ashleycole3054 9 жыл бұрын
Awesome Video
@blessengeorge40
@blessengeorge40 7 жыл бұрын
Awesome sauce!
@arfzp
@arfzp 3 жыл бұрын
love u from iran semnan university
@TusharMudgal
@TusharMudgal 9 жыл бұрын
very well explained..
@garrettguitar6583
@garrettguitar6583 4 жыл бұрын
@1:30 "The link to that video is also attached in this video here" No it's not. What is a heap? I don't know
@swagatpatra2139
@swagatpatra2139 4 жыл бұрын
google Priority Queue
@saniltalathi
@saniltalathi 7 жыл бұрын
Great work
@sayed200626
@sayed200626 8 жыл бұрын
Thanks for your nice tutorial. You have mentioned this method inside Vertex class. Can you please describe this method @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (int) (id ^ (id >>> 32)); return result; }
@AP-eh6gr
@AP-eh6gr 8 жыл бұрын
awesome, thanks a lot
@harshitagarwal5188
@harshitagarwal5188 8 жыл бұрын
in this vedio u used heap+map to store the information about all the non-evaluated node, but ur implementation is in java, i wanted to know do we have something like that in c++ too, i though of using an array but finding minimum item in it would be O(size of array) and that is a costly affair, hope to get some help.
@harshitagarwal5188
@harshitagarwal5188 8 жыл бұрын
i had used set and map to implement that, i thought of using priority_queue but at the time i didn't know how to make a min priority_queue in c++(since it is max priority queue by default), although i now know that , anyways thanks
@snehakathare572
@snehakathare572 6 жыл бұрын
Awesome....! thnx
@NitinNataraj-gf3vx
@NitinNataraj-gf3vx 7 жыл бұрын
god bless your soul
@shubhamojha3948
@shubhamojha3948 9 жыл бұрын
really helpful
@ULTIMATEGONANALIVE
@ULTIMATEGONANALIVE 8 жыл бұрын
how can we update the distances, once the variable is sent in priority queue?
@taoxie1991
@taoxie1991 8 жыл бұрын
I think the easiest way is to remove the element and insert a new one.
@pankajkalania5
@pankajkalania5 8 жыл бұрын
at 8:30 time what would be the value of D in Map+heap table if AD edge have weight
@9990490677
@9990490677 8 жыл бұрын
The value of D would be = Weight of edge AD(less than 7)
@HappyLearningSchoolCollege9294
@HappyLearningSchoolCollege9294 3 жыл бұрын
nice
@tempregex8520
@tempregex8520 6 жыл бұрын
Hello @Tushar Roy why are we not using java.util.PriorityQueue and instead our own version using BinaryMinHeap? can someone explain?
@harsheshshah5343
@harsheshshah5343 7 жыл бұрын
Bro your voice tore my ear drums, but aside from that good tutorial!
@veeral7632
@veeral7632 8 жыл бұрын
is Dijkstra's algo, a greedy method or dynamic or both?
@MrDivad006
@MrDivad006 7 жыл бұрын
You got the time complexity wrong. According to Fredman & Tarjan (1984), it should be O(E + V*log(V)) .
@abhishekchaudhary2951
@abhishekchaudhary2951 9 жыл бұрын
well explained (y)
@swatimaurya5424
@swatimaurya5424 7 жыл бұрын
Thank you.sir.
@vyomkjain
@vyomkjain 8 жыл бұрын
How to find w when both value are same... Which one should be considered as minimum?
@9990490677
@9990490677 8 жыл бұрын
Thank you. :)
@WeViral121
@WeViral121 5 жыл бұрын
WHY WHY in The world when a programmer is born he says "Hello World" :)
@SanjeevkumarMSnj
@SanjeevkumarMSnj 7 жыл бұрын
Where is the link for graph class?
@animeworldz575
@animeworldz575 6 жыл бұрын
can we use priority queue of java.util package in place of our min heap ??
@wwxk123
@wwxk123 8 жыл бұрын
anyone know where the Vertex class came from in his code? I'm assuming its his own implementation
@sudheerkumar4130
@sudheerkumar4130 8 жыл бұрын
Yes , its his own implementation. Graph ds can be implemented in lot of ways. Check his github github.com/mission-peace/interview/blob/master/src/com/interview/graph/Graph.java
@rubenashughyan4273
@rubenashughyan4273 8 жыл бұрын
why didn't you just use set, or priorityQueue and prefer Heap and Map together
@oshogarg5215
@oshogarg5215 6 жыл бұрын
You are GOD level in Algorithms...
Prim's Algorithm Minimum Spanning Tree Graph Algorithm
19:13
Tushar Roy - Coding Made Simple
Рет қаралды 295 М.
3.6 Dijkstra Algorithm - Single Source Shortest Path - Greedy Method
18:35
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 3,4 МЛН
The hidden beauty of the A* algorithm
19:22
Polylog
Рет қаралды 923 М.
Floyd Warshall Algorithm All Pair Shortest Path Graph Algorithm
19:26
Tushar Roy - Coding Made Simple
Рет қаралды 148 М.
Dijkstra's Algorithm:  Another example
8:41
barngrader
Рет қаралды 803 М.
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,4 МЛН
N Queen Problem Using Backtracking Algorithm
18:04
Tushar Roy - Coding Made Simple
Рет қаралды 343 М.
G-41. Bellman Ford Algorithm
27:43
take U forward
Рет қаралды 258 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН