Lecture 17: Bellman-Ford

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

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

  • @ChrisLeeX
    @ChrisLeeX 9 лет назад +263

    "Polynomial time is great, exponential time is bad, and infinite time gets you fired". Love it!

    • @magno5157
      @magno5157 5 лет назад +2

      At Google, quadratic time is bad.

    • @hektor6766
      @hektor6766 5 лет назад +3

      If he hasn't convinced everyone already, there's further proof of what a great prof he is.

  • @sergeykholkhunov1888
    @sergeykholkhunov1888 3 года назад +35

    01:52 graph requirements on the Bellman-Ford algorithm
    04:28 review of generic shortest-path algorithm
    06:40 first problem with generic shortest-path algorithm
    07:45 second problem with generic shortest-path algorithm
    11:29 Bellman-Ford
    15:54 complexity of Bellman-Ford
    18:02 correctness of Bellman-Ford
    23:24 proof of the theorem (relaxation part)
    30:22 proof of the corollary (check part)
    33:35 questions
    39:20 shortest-path vs longest-path

  • @user-td8zb9xo9k
    @user-td8zb9xo9k 3 года назад +16

    who are there watching these beautiful lectures in 2022 also? Because i feel it was much better way of explaining the things previously as compare to now where all the things are explained in ppts.

  • @proximush
    @proximush 4 года назад +13

    Amazing lecture. Some remarks:
    1) In the proof of correctness (at 24:28) you don't need to pick a shortest path with the minimum number of edges. Any shortest path will do (always assuming that the graph has no negative cycles).
    2) In the example (at 35:00) the professor affirms that you fix at the beginning an ordering of the edges and at each pass you relax the edges following that order. This is not strictly necessary for Bellman-Ford to work, as you can see from the proof of correctness. At each pass you can use any ordering of the edges.
    3) This is more of a philosophical remark, connected to point 2), on how one could think about Bellman-Ford. Once one figures out that relaxing edges is the way to go to find shortest paths you need to choose in which order to relax them. This is nontrivial because the relax operation is non-commutative: if you first do relax(a,b) and then relax(b,c) you end up with different distances than if you do relax(b,c) and then relax(a,b). Bellman-Ford comes up with an ordering of the operations relax(a_i, b_i) such that if (s,v_1,v_2,..,,v_k) is a shortest path from s to v_k then the subsequence relax(s,v_1), relax(v_1,v_2), ..., relax(v_{k-1}, v_k) will appear for sure (in this order!), and this is enough.

  • @derekchen6975
    @derekchen6975 10 лет назад +27

    You gotta love 42:40 when he catches an honest mistake, especially if you were able to see it first. The professor is brilliant, no doubt, but he is also human.

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

      why are you so cute?

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

      I love the part after the correction when the prof asked the other student, "and why did you say undefined?". "That's wrong." hahahah

  • @nikhilbelure
    @nikhilbelure 5 лет назад +11

    it feels like im in class, learning and at the same time reading and writing comments , like talking with classmates , loved it !!

  • @gregmakov2680
    @gregmakov2680 5 лет назад +6

    "5 minute university" sugestion is the point I like most in the lecture. Great, man!!

  • @bilalaytekin6282
    @bilalaytekin6282 4 года назад +7

    It is fantastic how he runs a Bellman-Ford at 43:20.

  • @thecuriousone12
    @thecuriousone12 10 лет назад +24

    I love this teacher!

  • @ashutoshtiwari4398
    @ashutoshtiwari4398 3 года назад +4

    Two key moments:
    42:40 Finding his mistake
    and
    43:20 Running Bellman Ford

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

    46:05 the reason why Bellman-Ford can not find the reachable shortest "simple" path when there exist any negative cycles : you potentially go through negative cycle before you reach the destination, hence |V-1| passes might not be enough, which makes this NP-hard. Also, finding the longest path is equivalent to finding the shortest simple path.

  • @weiboliu6095
    @weiboliu6095 5 лет назад +7

    correctness proof of bellman ford algorithm starts at 18:08

  • @ms97
    @ms97 4 года назад +3

    Clean explanations, easy to understand, thank you very much.

  • @jan1337
    @jan1337 11 лет назад +29

    free acapella concert!!!

    • @DarkLordAli95
      @DarkLordAli95 7 лет назад +3

      I wanted to go, but had to study for the quiz he mentioned in class....
      JK. I don't go to MIT :(

  • @barsopiavivek
    @barsopiavivek 8 лет назад +2

    26:22 how does only one relaxation give shortest path between two adjacent vertices.
    there could be v0->v2->v1 path which is shorter than v0->v1.
    thanks in advance

    • @paulsalvatore3935
      @paulsalvatore3935 8 лет назад

      I think in the case you mentioned it does give the shortest path between two adjacent vertices, those adjacent vertices being v0 and v2.
      It does not necessarily need to give the shortest path between all adjacent vertices but since every edge is explored, at least one will be the shortest path.

    • @Damian-cd2tj
      @Damian-cd2tj 8 лет назад +2

      In first place, I think he should have say the first iteration of the for loop. Because each iteration makes |E| relaxations. So the second relaxation will be in the first iteration of the loop.
      But anyways, you have to run the entire for loop even if you wanna get the shortest path between 2 adjacent nodes.
      But at the end you'll figure out that if the shortest path between was v0->v1 then it was given in the first iteration of the for loop.
      If the shortest path was v0->v2->v1 then it was given in the second iteration.
      But you wouldn't know until you run the entire algorithm.
      It is a bit tricky because basically, after 5 iterations you will have all the shortest paths consisting of 6 nodes, and you will also have paths of 6 nodes that are not the shortest, but you won't know which one are which until you finish.

    • @harrypotter-el4lx
      @harrypotter-el4lx 4 года назад

      it does not .it gives only current shortest path which will be updated once we relax edges coming out of v2 which wi;; be the shortest path of v0 to v1

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

      because we already know that v0 -> v1 -> .... -> vk is a shortest path, that means all sub paths are also shortest paths, so v0 -> v1 is a shortest path from v0 to v1, there could be no shorter paths (otherwise v0 -> v1 -> .... -> vk won't be a shortest path from v0 to vk).

  • @fabiencedric6665
    @fabiencedric6665 8 лет назад +3

    @10:59 How does dijkstra turn into exponential time?

    • @nitskrishna
      @nitskrishna 8 лет назад

      see @ 6:51 , he says for a graph if edges are selected wrongly and then complexcity in terms of number of vertices.

  • @saraconde9172
    @saraconde9172 9 лет назад +1

    great lectures, help me a lot.

  • @IlkerDeligoz
    @IlkerDeligoz 8 лет назад +2

    while negative cycles cause shortest path to be undefined, positive cycles do the same for longest path. so in a sense, if you negate everything and run B-F undefined result is still correct, isn't it?

    • @loganwishartcraig
      @loganwishartcraig 7 лет назад

      Yeah, that's what I thought too. I think he may have been referring to trying to find the longest *simple* path from s to v (i.e. not including cycles) which would be 6 in that example, but because of the cycle, would cause BF to return undefined.

  • @alinradulescu7068
    @alinradulescu7068 10 лет назад +71

    You came here for 11:33 - 15:20

    • @clapika999
      @clapika999 10 лет назад +1

      um why?

    • @alinradulescu7068
      @alinradulescu7068 10 лет назад +2

      Toan Ngo The Bellman ford algorithm is explained in that interval. Since the video is named "Bellman Ford", this is what you searched for, and if you only want to understand how does it work, those 4 minutes are enough to understand it.

    • @clapika999
      @clapika999 10 лет назад +15

      Alin Radulescu those 4 minutes don't really show how it works - it's just the algorithm. Well, at least I won't truly understand B-F just by looking at the algorithm.

    • @syyamnoor9792
      @syyamnoor9792 7 лет назад +1

      Not all heroes wear a cap

    • @李愚-f7j
      @李愚-f7j 6 лет назад

      hahahah

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

    I don't understand what he is proving?

  • @theFlutterDeveloper
    @theFlutterDeveloper 11 лет назад

    In worst case every pair of vertices is connected by an edge. So the number of edges will be (n choose 2), which is n*(n-1)/2. That's about n^2 edges.

    • @AdityaPratapsingh9125
      @AdityaPratapsingh9125 7 лет назад

      Can you please explain how would there be an exponential number of edges in the generic shortest path algorithm?

    • @汤晓波-s7s
      @汤晓波-s7s 7 лет назад

      I got the same question, why exponential?

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

    Think about coin change problem, how similar they are.

  • @MuhsinFatih
    @MuhsinFatih 6 лет назад

    what if you do 3 passes of E passes? 1 - first O(VE) pass, 2 - check pass (marking bad edges), 3 - another O(VE) pass skipping bad edges. I think that would give the simple shortest paths

  • @mostafasaadinasab6338
    @mostafasaadinasab6338 5 лет назад +1

    #besten #Episode Full Service#Vielen Vielen dank#bestimmt Liebe grüße und zu Videos#so#mit#

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

    K

  • @kevinryzack5712
    @kevinryzack5712 6 лет назад +3

    This guy doesn't explain why after relaxing each edge E, V-1 times, why we're guaranteed to have found the shortest path assuming no negative cycles. That seems to be a big point. At 28:49, he writes on the board, that after the second pass we get delta of (S, V2) because in second pass we relax (V1,V2)..But we relaxed (V1, V2) in all passes since in all passes we relax each edge, according to the algorithm.
    Kinda frustrating

    • @kevinryzack5712
      @kevinryzack5712 6 лет назад +2

      This lecture has a much better explanation. The first 50 minutes goes over it:
      ruclips.net/video/XIAQRlNkJAw/видео.html
      Shai Simonson is great. He's not currently an MIT lecturer, but I believe he gave that lecture when he was working at MIT. Go figure.

    • @SchoolVideosGoHere
      @SchoolVideosGoHere 5 лет назад

      @@kevinryzack5712 Thanks for the share; I had the same thought about that portion and was going to rewatch the video/read CLRS to see if I missed something (which I probably will do), but glad to see another lecture!

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

      @@kevinryzack5712 Had the same doubt. Went through a lot of resources and explanations, but couldn't find a better and intuitive explanation than this. Thanks for sharing.

  • @kevinryzack5712
    @kevinryzack5712 6 лет назад +2

    I've watched most of the lectures so far and this one is pretty bad. Recitation is definitely needed here. Viktor where are you!!

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

    Are there other algorithms which could produce negative cycles?

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

      any weighted general graph containing (-)ve weights can be solved using bellman-ford where as other algorithms are all specific case related which is outside the scope of 6.006

  • @seemaverma279
    @seemaverma279 11 лет назад

    excellent .....

  • @AlexanderList
    @AlexanderList 8 лет назад +1

    What does -ve stand for?

    • @GopalSub
      @GopalSub 8 лет назад +6

      +Alexander List Negative

  • @knowledge2memory
    @knowledge2memory 11 лет назад

    perfect video - thanks for sharing ;-)

  • @MrRockashish
    @MrRockashish 9 лет назад

    can anyone tell me why negative weights are used?

    • @AnukulSangwan
      @AnukulSangwan 8 лет назад +8

      +Ashish Yadav There could be various situations. Consider this, if you travel from city A to city B you earn 50 rupees (+50), but if you travel from city B to city C you spend 20 rupees (-20).

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

      An example would be traveling by boat up river ...

    • @nayankumarbarwa4317
      @nayankumarbarwa4317 Год назад +1

      @@icaryslittle6370 Nice example

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

    at 4:44 , *throws hat in the air*

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

    This doctor has mistaken concept of single source shortest path to shortest simple path.

  • @patrickyue6264
    @patrickyue6264 9 лет назад

    Could any one please explain why is the exponential time? 7:03 Thanks

    • @chengmingzhu450
      @chengmingzhu450 9 лет назад

      +Pengqian Y see lecture 15

    • @석상주
      @석상주 9 лет назад

      Pathological selection of edge is pretty vague but It's clear that there is an exponential number of paths, where length of each path is at least 1 (or there is at least one edge). In particular, the number of paths from 1 to n-1 is 2^((n-1)/2) and we have this many choices of d[n-1]. In the worst case, it will try all of them and relax d[n-1] + (n-1, n)

  • @sunitsingh9182
    @sunitsingh9182 10 лет назад

    question .. why is the geeric algorithm's complexity O(2^n/2) ...somebody please help :)

    • @sunitsingh9182
      @sunitsingh9182 10 лет назад

      R. S. Joshi ahh! bad bad typo :P
      thank you sir :) the proof makes the point so concrete!

    • @prodev7401
      @prodev7401 9 лет назад

      Suneet Singh is this the Efficient implementation because i think there is other solution with DP ?

    • @sunitsingh9182
      @sunitsingh9182 9 лет назад

      Pro Dev bellman ford is kindda dynamic programming right? unlike dijkstra's greedy criterion, bellman ford relaxes all the edges and gauges shortest distance then...
      what is the other solution anyway??

    • @prodev7401
      @prodev7401 9 лет назад

      on this video this solution is effcient implementation for Save Space there is other solution the Original ;)
      ruclips.net/video/OQ5jsbhAv_M/видео.html see min 49

    • @prodev7401
      @prodev7401 9 лет назад

      True ... ?

  • @nicholastan3027
    @nicholastan3027 11 лет назад

    im sorry, but why is E order V^2?

    • @siddhartha.saif25
      @siddhartha.saif25 7 лет назад +2

      In worst case every pair of vertices is connected by an edge. So the number of edges will be (n choose 2), which is n*(n-1)/2. That's about n^2 edges.

    • @loganwishartcraig
      @loganwishartcraig 7 лет назад

      With digraphs, I think it's just n*(n-1) since every node can be connected to every other node, resulting in two edges per node pair. (since E(u, v) != E(v, u) in a digraph). Think you're right for undirected graphs though. Still O(v^2) either way.

    • @MuhsinFatih
      @MuhsinFatih 6 лет назад

      @@loganwishartcraig That's not important. The point of analyzing complexity is understanding "in terms of what and how is your algorithm's time growing". For example, in Bellman-Ford, you are doing a check pass also, but you don't count the total complexity as O(VE + E), which technically is O((V+1)E), you say O(VE).

    • @rajawez4535
      @rajawez4535 5 лет назад

      Think of adjacency matrix.

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

    42:40 that was funny :D

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

    i dont really understand the loop, where he loops v-1 times? can someone please help.

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

    This is too edgy for me

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

      Ha! I get it. It's a bit graphic for my tastes, but a good joke nonetheless.

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

    I don't think people should get to have trivial algoirthm named after themselves

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

      this is my algorithm for calculating the sum of a collection of numbers.. for i in collection: sum += i PUT ME IN TEXTBOOK

    • @theendurance
      @theendurance 4 года назад +1

      @Lizard King its not about triviality, its about novelty. It was new, so it was recognized. Yours isn't new.

  • @lolno6527
    @lolno6527 8 лет назад +17

    MIT has an endowment of $13.182 billion, I wonder why it needs donations lol.

    • @DarkLordAli95
      @DarkLordAli95 7 лет назад +3

      LMAO right??! that's what I always wonder whenever I hear that bit...
      you need donations? for realsies now???

    • @Saganist420
      @Saganist420 7 лет назад +6

      We're talking about the American Educational system here... they can never have enough money. Maybe only american hospitals are more obsessed with money than private colleges.

    • @dylancutler1978
      @dylancutler1978 6 лет назад +12

      They're asking for donations for their open courseware, which is harder to get funding from the college administration. Why would the administration fund giving away the information for free? Open education is academia's last weapon against the commodification of information.

  • @PixelPulse168
    @PixelPulse168 9 лет назад +2

    So, what exactly is difference between Dijkstra and Bellman-Ford?

    • @chengmingzhu450
      @chengmingzhu450 9 лет назад +3

      +Liang Luo different assumptions about the graph, different complexity, and of course, different algorithm.

    • @KRCPrice
      @KRCPrice 9 лет назад +8

      +Liang Luo Dijkstra won't work with negative edges.

    • @houssemdhiab7337
      @houssemdhiab7337 9 лет назад

      +Liang Luo the difference is that belman ford can solve a cycle where you have negative values

  • @BrokenHeartanindo
    @BrokenHeartanindo 9 лет назад

    many things are not expalined in this video lecturer is giving short dialogs as if allpeople in the world is genius so please expalin every thing if you put something in youtube

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

    i need to learn math

  • @andrewpersaud4144
    @andrewpersaud4144 7 лет назад +5

    i wish this guy taught all the videos. don't understand the white dude

    • @csl1384
      @csl1384 5 лет назад +1

      Some of us prefer Eric (if saying the the "brown dude" is racist, isn't saying the "white dude" racist too, here is a question for you to meditate on), can't make all people happy all of the time.

  • @BrokenHeartanindo
    @BrokenHeartanindo 9 лет назад

    see in ur comment box if every one can understand yoyr video no one will ever ask the question...bdw i had understand this from another book of indian mtech author...

    • @calyxwakefield3523
      @calyxwakefield3523 9 лет назад +2

      +Broken Heart first of you grammar is terrible and secondly you are not paying them for this lecture so stop talking trash, if you have doubts ask

    • @dhruvjoshi8744
      @dhruvjoshi8744 5 лет назад

      @@calyxwakefield3523 exactly,he is like i want it free ,i will never donate, but will give my precious advice ...SOAB!