Lecture 16: Dijkstra

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 145

  • @sergeykholkhunov1888
    @sergeykholkhunov1888 3 роки тому +64

    00:46 last lecture review
    05:55 proof of relaxation correctness
    17:36 DAG example with neg. edges (using topological sort)
    27:43 Dijkstra demo ("greedy gravity")
    33:29 Dijkstra pseudo-code
    41:10 example
    44:50 time complexity

  • @NaineelShah
    @NaineelShah 10 років тому +93

    27:41 Dijjkstra's Algorithm

    • @X37BEX
      @X37BEX 9 років тому +4

      Naineel Shah Balls!!!
      Literally...

    • @DarkLordAli95
      @DarkLordAli95 7 років тому +1

      balls hanging.
      eyyy that's why I'm not in MIT.

    • @groku0112
      @groku0112 7 років тому

      Naineel Shah thank you

    • @klev_s7635
      @klev_s7635 7 років тому

      thank you man

    • @07sakib
      @07sakib 6 років тому +9

      id still recommend to watch the whole video to understand how the algorithm is actually working, instead of just writing code, in which case, stackoverflow is a better option

  • @MrCarl614
    @MrCarl614 11 років тому +10

    Had the samce lecture at my state university, it is very evident that MIT has the best professor. He was clear and very understandable; made a complex topic very easy to pick up.

  • @thisprofileismt
    @thisprofileismt Рік тому +7

    The mechanical demonstration is exactly the kind of thing you go to school to learn. Lovely demo. Such a cool way to think about the algorithm

  • @lakhanbairwa5646
    @lakhanbairwa5646 3 роки тому +13

    I was making my project on Dijkstra algorithm....and suddenly found this .... amazing content from MIT ... thank you MIT .... I will explore and try to learn as much I can ☺️

  • @WilliamHolden0
    @WilliamHolden0 7 років тому +110

    Love the mechanical demonstration!

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

      Headline news for Facebook: Researchers propose a new way of calculating shortest distance but their database literally has 6B marbles :)

  • @vinc456
    @vinc456 8 років тому +105

    Can you imagine a classroom lecture being broadcast to an audience of 85k? These are the times we live in.

  • @chanpol321
    @chanpol321 8 років тому +31

    A greedy algorithm is an algorithmic paradigm that follows the problem solving heuristic of making the locally optimal choice at each stage[1] with the hope of finding a global optimum. In many problems, a greedy strategy does not in general produce an optimal solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time.
    For example, a greedy strategy for the traveling salesman problem (which is of a high computational complexity) is the following heuristic: "At each stage visit an unvisited city nearest to the current city". This heuristic need not find a best solution, but terminates in a reasonable number of steps; finding an optimal solution typically requires unreasonably many steps. In mathematical optimization, greedy algorithms solve combinatorial problems having the properties of matroids.

  • @adamvs1
    @adamvs1 10 років тому +239

    Again, great lecture, but too tight with the camera angles: we generally need to see two backboards at once, not a closeup of the back of his head.

    • @junweima
      @junweima 6 років тому +6

      Just open the lecture notes pdf from the website

    • @reyadhasan6318
      @reyadhasan6318 6 років тому +4

      @@junweima where plz

    • @dipakraut6058
      @dipakraut6058 5 років тому

      @@junweima But they are for username and password

    • @utkarshankit
      @utkarshankit 5 років тому +4

      @@dipakraut6058 ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-notes/

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

      @@junweima Thanks for the suggestion, it helped me !

  • @divyeshbhartiya
    @divyeshbhartiya 4 роки тому +6

    This guy is a sheer genius. He takes so much efforts to make students understand what the thing is and the motivation to do so...Really amazing..!!

  • @turinreza
    @turinreza 9 років тому +3

    At 17:50 Algorithm for Dags (can have negative edges) (1st step Topological sort then 1 pass of relaxation from any source node)

  • @melvin6228
    @melvin6228 5 років тому +23

    For people who are brushing up their algorithm courses and have seen Dijkstra already, I recommend the following:
    1. Subtitles on
    2. 2x playback speed
    No practice needed, as you'll mostly read the subtitles and just quickly confirm whether what he said was the same thing.

  • @tchappyha4034
    @tchappyha4034 5 років тому +17

    15:38 Relaxation is safe but this professor is dangerous.

  • @cparks1000000
    @cparks1000000 4 роки тому +15

    This was a wonderful lecture. I finally understand Dijkstra's algorithm fully.

  • @JohnDoe-nr5zi
    @JohnDoe-nr5zi 5 років тому +3

    Analysis of different data structures for implementation of Dijkstra's queue:
    44:52

  • @anthienvo
    @anthienvo 6 років тому +10

    Wow, the moment dr. Devadas said "alright let's work on an example of this to be clearer," I almost jumped out of the chair full of joy

  • @basi4869
    @basi4869 5 років тому +16

    LOL, "for posterity" at 28:49. Thank you professor!

  • @sharma20101000
    @sharma20101000 11 років тому +2

    He knows the stuff very well.
    Very simple and effective to describe

  • @therealhaxwell
    @therealhaxwell 8 років тому +17

    I wonder if he has any more cushions...

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

    00:01 Dijkstra's algorithm is a concrete algorithm for finding shortest paths.
    03:14 Reconstructing the shortest path using predecessor and pi values.
    09:16 The shortest path algorithm involves picking and relaxing edges until optimal delta values are obtained.
    12:39 Triangle inequality and its application in shortest paths
    17:36 DAGs (Directed Acyclic Graphs) are useful for finding shortest paths without negative cycles.
    20:22 Dijkstra's algorithm is a special case shortest path algorithm that takes order v plus e time.
    25:26 Final values obtained using Dijkstra's algorithm for a graph without cycles.
    27:35 Dijkstra's algorithm is a greedy algorithm that incrementally builds the shortest paths.
    31:35 Dijkstra algorithm greedily constructs shortest paths
    33:26 Dijkstra algorithm initializes the graph, sets, and vertices for finding the shortest paths.
    39:04 Read the formal proof for Dijkstra
    41:04 Dijkstra algorithm execution steps
    46:42 Dijkstra implementation with an array structure has a complexity of theta v squared
    49:18 Dijkstra's algorithm has a complexity of theta v log v plus e time.
    Crafted by Merlin AI.

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

    i literally don't get the triange inequality or why it's being used.. the weights of edges don't have to bear any resemblance to actual geometry.. and literally in his first example he had an example of a triangle where 3 < 1+1 which breaks that inequality.. WOT?

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

      It's not the weight of the edges ... it is the shortest path that is being compared ... helpful in writing proofs of correctness

  • @jsviel
    @jsviel 6 років тому +3

    dijkstra's algorithm 27:41

  • @wmd5645
    @wmd5645 5 років тому +9

    Why is the term 'relax" used? Im guessing infinity is too stressful?

    • @jamesbalajan3850
      @jamesbalajan3850 5 років тому

      Nice joke!

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

      Good question! This is addressed in CLRS:
      "
      It may seem strange that the term “relaxation” is used for an operation that tightens an upper bound.
      The use of the term is historical. The outcome of a relaxation step can be viewed as a relaxation
      of the constraint v.d

  • @user13823
    @user13823 9 років тому +3

    At 48:20 he writes O(V*V + E*1) = O(V^2), and says: "because E is order V^2".
    Then at 51:00 - he writes just O(V lgV + E). But he said earlier that E is order V^2, so it means that O(V lgV + E) in worst case becomes O(V lgV + V^2), and this is again order O(V^2). So, in worst case Fibonacci heap does not help.

    • @DarkLordAli95
      @DarkLordAli95 7 років тому +1

      hmmm good observation...
      I guess just like in many things in CS, we just have to learn it even though we already know something better/just as good and easier.

    • @siddhartha.saif25
      @siddhartha.saif25 7 років тому +2

      if the graph is such that every vertex is connect to every other vertex, then E =O(v^2). if that is the case then the array implementation and fibonacci heap implementation both will be of O(v^2). but if that's not the case, then array implemenation will still be O(v^2) but now fibonacci heap's complexity will become O(vlogv + E). That's what i understood

    • @dorsal937
      @dorsal937 6 років тому

      You're right, but worst case it's not the only interesting case there is.
      Like, if we had a succession of graphs where E grows linearly with V for some reason, then worst case Fibonacci would be O(V Log V) which would be better than O(V^2).
      That's why we'd lose a bit of information if we'd just say the Fibonnacci implementation is O(V^2). On the other hand, dropping the E in O(V^2 + E) is fine, because V^2

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

      @@dorsal937 >=*

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

      It depends on the graph. For graph with a lot of edges, sure. But not all graphs are like that, so it’s still useful to find all sort of optimisations, bc for some graphs they still lower the execution time substantially in practice.

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

    Great lecture. 39:30, Yeah I have a question. You don't actually show when you put the nodes into the queue. I was assuming that it was when you first visit the node, but in practice, this didn't seem to work. I had to reinsert them back into the queue if I changed d[u]. So, does that mean that this is not actually O(V+E)? Could the worst case be O(V*E)?

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

    2:52 Binary tensor factorization should be useful (at some point), especially if the graph has structure.

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

    28:30 -- incredible, intuitive model of Dijkstra

  • @n92
    @n92 8 років тому +4

    Excellent Tutor. Typical MIT style

  • @MrSmeeds
    @MrSmeeds 6 років тому +1

    The functions d and delta describe the minimum weight paths, NOT the shortest paths. This is an important distinction that gets blurred a few times here

  • @jimnewton4534
    @jimnewton4534 5 років тому +1

    Great lecture. The mechanical demonstration is really nice. Thanks.

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

    awesome course lessons. really good stuff here

  • @李愚-f7j
    @李愚-f7j 6 років тому +4

    speed up at 2x,easier to focus on key point for me. no need to pause and write down everything,it will slow down my speed of understanding

  • @ericka.montanez6821
    @ericka.montanez6821 3 роки тому +1

    after that demo there is no way I forget again how to do Dijkstra

  • @mitchellerblich4044
    @mitchellerblich4044 5 років тому +1

    Interesting another lecture about paths without using the term "hops" or that routers use these algorithms.

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

    The Dijkstra's Algorithm in the example ending at 44.56 is not complete...
    2 more steps pending which should get the following result in Q -> {0,7,3,9,5}
    the shortest path to D from the source is 9 and not 11..
    if I'm not mistaken , the shortest paths are as follows :-
    A->B = 7, A->C = 3, A->D = 9, A->E = 5.. .
    had he completed the next two steps , this would be the answer.. Anyone like to back me up on this or maybe correct me if I'm wrong pls..

  • @maneesh541
    @maneesh541 11 років тому +4

    Professors voice and personality reminds me of Dr Sheldon Cooper

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

    The Induction used at 10.00 seems pretty unclear to me. It says quitely vaguely that induction is used over the number of steps?

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

    C’est absolument magnifique!

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

    I do not understand the proof.

  • @raymondchua280
    @raymondchua280 11 років тому +7

    Why is O(E) = O(V^2)?

    • @blazkelbl
      @blazkelbl 11 років тому +8

      Because every vertex can be connected to every other, therefore binomial(|V|,2) = O(|V|^2)

    • @raymondchua280
      @raymondchua280 11 років тому +1

      Blaz Kelbl Thanks! :)

    • @cskwillreturn2473
      @cskwillreturn2473 7 років тому +2

      simon mikalsen
      I think you are talking about the undirected graph. Binomial works for directed.
      Assume two vertices v1 and v2. The total number of possible edges would be 4 which is 2^2 ( 2= total number of vertices). All possible edges v1 -> v2, v2 -> v1, v1->v1, v2->v2. They all add up to 4. But this is only correct if the graph is directed. If undirected, I think it should be v(v-1)/2.

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

      think of a completed graph

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

    here teachers do the work and yk in my school we had to prepare projects and yk thats a good question i used humiliates and told to go him if we asked remotely valid questions that the teacher didn even explain its the teachers that make this university i swear

  • @traveleer2922
    @traveleer2922 4 роки тому +5

    Takeaway of this lecture: Gravity is greedy and causes balls to hang....

  • @mitchellerblich4044
    @mitchellerblich4044 5 років тому

    I also thought that Dij ... can compute equal cost paths ...and unequal cost paths for balancing loads... not mentioned .. How to you determine pathing / routing loops? Why doesn't he mention these items?,

  • @alihelmi
    @alihelmi 6 років тому

    Dijkstra Algorithm 27:12

  • @fgfanta
    @fgfanta 5 років тому

    I believe there is a mistake in the pseudo-code for Dijkstra: relaxation should not be done for every vertex v adjacent to u, but only for those that are still in Q. Otherwise, you end up relaxing a vertex already extracted from Q and placed into S, further lowering its d; against the assumption that its d is final (equals delta) at the time you extracted it from the priority queue.

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

      you couldn't do that unless you had negative weight edges. Dijkstra assumes non-negative weight edges and it can shown by induction that a vertex v is removed from Q only when d(s,v) = delta(s,v)

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

      Relaxing such an edge won’t lower d for a vertex in S already. It might be unnessary to perform this relaxation, but it won’t break the algorithm, it’s not a mistake, technically.

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

    Holy sh*t! That demo was beautiful! I loved it!

  • @ilyakopyl
    @ilyakopyl 6 років тому +3

    Dijkstra is my homie.

  • @causereasons.4826
    @causereasons.4826 4 роки тому +2

    best lecture!

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

    amazing content!

  • @syedwaqarhussain8219
    @syedwaqarhussain8219 9 років тому +1

    I am so confused with the symbolic statements actually. is there any way I can practise and learn writing symbolic algorithm.

    • @satadhi
      @satadhi 7 років тому +1

      i think he used those symbol in a way that seems rather difficult than it actually is !

  • @PherricOxide
    @PherricOxide 11 років тому

    Dijkstra starts at 27:42

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

    Can someone help me with the code for this approach.

  • @smona-i5v
    @smona-i5v 6 років тому

    Why dijksta’s algorithm does not work if the graph has negative weight edge?

    • @alieser7770
      @alieser7770 6 років тому

      because it would always go back and fourth between the two nodes of that edge as the distance decreases every time.

    • @mohamednofal5256
      @mohamednofal5256 6 років тому

      Dijkstra priorities paths with small weights and might totally ignore paths with larger weights even though these paths weights might decrease in the future.
      for ex. if I want the shortest path from A to Z and I have two paths such as
      path 1 weights respectively : 5, 100, -105
      path 2 weights respectively: 8, 2, 5
      Dijkstra would walk like:
      path 1: 5
      path 2: 8
      path 1: 100
      path 2: 2
      path 2: 5
      and present path 2 as the shortest path

  • @kumarshubham8597
    @kumarshubham8597 6 років тому +5

    When do we call an algorithm safe?

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

      guessing from the lecturer it would be safe iff : it takes a finite no of steps to solve the problem and it solves the problem for all of its instances

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

      @@nanidachamman2645 now. Your answer has just made it interesting.

  • @dragonEX123456
    @dragonEX123456 7 років тому

    why is decrease key theta(1) but not theta(n), more keys longer time?

    • @DarkLordAli95
      @DarkLordAli95 7 років тому +1

      because with an array implementation, you can access elements in a constant time. array[0] = array[0] -1
      however, with a min heap, if you decrease the root (the vertex with the smallest weight) you will have to check if this root still satisfied the minHeap property (it should be smaller than both its children) if it isn't, then we'll have to call build min heap or on the root, to keep our min heap property, which takes logv time.

  • @Squirrelschaser
    @Squirrelschaser 6 років тому +4

    The camerawork on this one is awful. So zoomed in.

  • @ChrisLeeX
    @ChrisLeeX 9 років тому +1

    @11:00: That is not a proof by induction.

    • @dexterod
      @dexterod 8 років тому +2

      +Chris Lee It definitely is.

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

      He showed a base case and showed how relaxation works on (u,v). You assumed the principle holds for u and he proved it holds for v too and therefore generalizing it to every edge in the graph

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

    I had no idea ikea made algorithms

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

    Wonderful. Thankyou.

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

    For notes geeksforgeeks helps for Small revision.

  • @zijianzhang5984
    @zijianzhang5984 9 років тому +2

    He is more like presenting the Chapters in CLRS, rather than actually teaching.

  • @TaXue
    @TaXue 12 років тому

    i love these videos!

  • @GM-pk4li
    @GM-pk4li 2 роки тому

    why his voice is similar to a sundar pichai

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

    Ya like DAGs? Dijkstra does.

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

    I really would value more context as to why/how these things are important to know. Even if the answer to that is that I might need to be able to read a diagram some day.

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

      Have you used Google maps or any other kind of journey planner? )
      Isn’t it obvious why the problem of finding the shortest path is practical?

  • @yashjain6945
    @yashjain6945 6 років тому +1

    43:15

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

    Kara tahtayı özlemişim

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

    Tupolev Tu-95

  • @Youthemoneyguy
    @Youthemoneyguy 11 років тому +1

    lolll Professor Devadas you are hilarious

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

    press ctr + w to get question while watching the video

  • @manuvogt4590
    @manuvogt4590 5 років тому

    Could someone explain me why for every implementation of the data stucture Q!the time complexity of Dijkstra algo is O(|E| * complexity of decrease key + |V| * complexity of extract min) ? thanks !

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

      The algorithm extracts min at most |V| times and check each edge only once.

  • @sohamdats
    @sohamdats 8 років тому

    This man speaks like Christopher Walken :P

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

    I feel bad to be dumb

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

      You can be dumb in something’s once in a while. But not dumb in all things all the time. Hope abounds

  • @ukaszszczur5696
    @ukaszszczur5696 2 місяці тому

    This presentation about Dijkstra's algorithm is a joke-like showing something to kids. Look for an explanation given by Erik Demaine. He will treat you like an adult.

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

    why does he need a paper with him for the lecture? He is just reading off it and sounds like a robot. He should be smart enough to not rely on a paper telling him what to say.

  • @ZipingL
    @ZipingL 9 років тому +1

    stutters too much, choppy delivery too

    • @test143000
      @test143000 9 років тому +3

      +ElphaTutorials maybe it is just a case when you do not have enough mathematical background, start with Calculus Revisited by H. Gross

    • @divyasasidharan2960
      @divyasasidharan2960 8 років тому

      attend my school :P

    • @EverythingTechWithMustafa
      @EverythingTechWithMustafa 5 років тому

      Get tenured and teach man

  • @drewmandan
    @drewmandan 9 років тому

    OSPF reprasent

  • @CourtneyW-jr6fx
    @CourtneyW-jr6fx Рік тому

    Taking a mathmatics course and now referencing MLB Lenny Dykstra is so immature #twofoldreference you should be fired for wastubg resources that could have helped me be creating real effective change in communities but your a corrupt man who went behind my back with my aunt ( who would rather see me fail and not be joyful)

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

    I don’t like sewing donuts

  • @EliciaSheya
    @EliciaSheya 6 років тому +1

    he sounds like Rick from Rick and Morty... great lecture though.

  • @karesharunakirinathan4851
    @karesharunakirinathan4851 9 років тому +12

    Not explained very well. Hard to understand.

    • @evelyngalvan771
      @evelyngalvan771 7 років тому +15

      Karesh Arunakirinathan for you.

    • @ruhroh7042
      @ruhroh7042 6 років тому +4

      Compared to my class, this was explained extremely clearly.

    • @daddydangerous20
      @daddydangerous20 6 років тому +4

      @@evelyngalvan771 Bitch don't act so smart. This was a shitty explanation to a simple algorithm and you can't admit that.

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

      @@daddydangerous20 ehh it was pretty good. He didn't rush it

    • @causereasons.4826
      @causereasons.4826 4 роки тому +1

      @@daddydangerous20 this lecture is not for the people who just kno the name and steps of an algorithm. Go watch a 5min video on this topic 2x youll get what youre looking for. This lecture is meant for the students who create new algorithms. no one expects dumb people like you to solve a difficult problem. you just follow things blindly

  • @gabix123lg
    @gabix123lg 9 років тому

    like for posterity haha