Greedy Algorithms | Set 1 (Activity Selection Problem) | GeeksforGeeks

Поділитися
Вставка
  • Опубліковано 18 вер 2024
  • Explanation for the article: www.geeksforgee...
    Read More: www.geeksforge...
    This video is contributed by Illuminati.

КОМЕНТАРІ • 92

  • @JaDoggCoder
    @JaDoggCoder 4 роки тому +51

    I love how calm you talk. Your accent is also very easy to understand. :) Good stuff.

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

    I think for(j=i+1;j

  • @danielshahverdi7053
    @danielshahverdi7053 4 місяці тому +1

    Like always! Simple and understanding❤

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

    Can you tell me what to do in case the finishing times of two activities are the same? Do we sort by the difference between their respective start and end times or do we sort according to the finish time of the previous activity? As for example, here why is A6 selected first instead of A4?

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

      The answer would be same whichever interval you take first.

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

      I think we can just keep the one with largest start time when finish time is the same

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

    Very nicely explained which gives clear explanation and helps to understand the chapter better.

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

    please also discuss the algorithm analysis.

    • @GeeksforGeeksVideos
      @GeeksforGeeksVideos  7 років тому +3

      For the given problem, the time complexity is same as that of sorting the input, i.e., O(n log n).

  • @NishantKumar-pt5zj
    @NishantKumar-pt5zj 7 років тому +8

    Hi, can you please explain how you directly arrived at the 3 step algorithm for above problem?

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

    Sir if suppose there is a clash i.e. if the ending time and starting time of 2 activities are same then what should be the approach?

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

      If at all that kind of situation arises, then apparently you can select anyone of them but not both.

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

    Excellent explanation

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

    Very good explanation , concise and to the point.

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

    its very good, keep doing good work!!

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

    @geekforgeek
    update kr lo Bhai .. way of teaching

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

    But what if the question has multiple solutions, I mean to say what the max no of activities can be done starting from pos n rather than from 1st.

    • @piyusharora5327
      @piyusharora5327 6 місяців тому

      Then use dynamic programming. Greedy approach does not always give globally optimum solution.

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

    Thanks from Turkey :))

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

    very nice and clearly!! Thank you😊💕

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

    the last example ithink we should sort them according to start time not end time

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

    just wanna ask how did u guys sort the starting array?
    did u change the index value of starting array with respect to the finish array???
    assuming after doing sort on finish array, then u sorted the starting array?

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

      use any method of sorting

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

      First store value of start[i] and end[I] in pair and store this pair another vector and then sort that vector on the basis of second value of pair

  • @mdarshhamza8661
    @mdarshhamza8661 5 місяців тому

    Sir,If I want to learn python ,
    Then in the interview will they allow me to use built in libraries of it or how I am confused to choose that which language i have to learn it's just i have a very basic idea of Java ,python and javascript so which language would u suggest me to learn ...please guide me in this

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

    Doubt clear thanks buddy

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

    short and sweet

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

    please provide a detailed run time analysis since I was poor in calculating .

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

    nice explanation

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

    Thank you sir

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

    if unsorted,using java we can use Array.sort() and then do the needful no?

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

      if it's unsorted , then we have to sort them according to their finish time. So Arrays.sort() will not do the task, you have to use comparator.

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

    What if in unsorted input we print sequence of activities while insertion/merge sort on input? Is it possible that we may loose data in such case?

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

    Please increase the volume of the video

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

    The sorting was not stable. what if it was (5,9) would have have came before(8,9) then how would you approach?

    • @AbhishekSingh-lk5wj
      @AbhishekSingh-lk5wj 5 років тому

      same approach since start time of (5,9) is less than the finish time of (5,7) so it will skip (5,9) and eventually print (8,9).

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

    Why does it feel like the same person has given voice overs in Neso academy's digital electronics videos?

  • @RaushanKumar-co3wj
    @RaushanKumar-co3wj 7 років тому +1

    How for unsorted input it will take nlogn can you elaborate ?? . I am thinking maybe this is the answer just verify .
    O() = O(sorting) + O(Activity Selection)
    = O(Quick sort average case) + '''"
    = nlogn + n
    = nlogn
    ??

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

    Sir your explanation is excellent ,but my humble request is run the code which is explained in video ,and upload along with this video

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

    Please Improve the Quality of the video... 360p is a bit low.... and the code does not appear clearly because of it..

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

      Neeraj Prakash you can have the code from geeksforgeeks site

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

    Anyone please explain why we are always considering first time.

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

    i beg you please tell about the Maximum Independent set ,Local Improvement or local exchange trick in Activity selection problem

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

      Hi Achin,
      I have never heard of the local improvement/local exchange trick. Could you please share some resource? I can't find anything relevant on Google either.

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

    I'm struggling to find an algorithm that works with these 2 tests in the cases when there is 1 person and 2 people able to perform tasks:
    [[1, 2], [4, 5], [6, 7], [3, 8]]
    should output: 3 (1 person), 4 (2 people)
    [[1, 4], [2, 6], [7, 9], [5, 10]]
    should output: 2 (1 person), 4 (2 people

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

      You can solve the problem by again calling the same function and check for the remaining elements, adding up both the results in the end.

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

    are we using merge sort technique?

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

      who gives a damn but probably quicksort

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

    excellent, thank you

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

    thanks

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

    Can you explain me about activity compare.

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

    how unsorted list has more time complexity then Sorted list??

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

      Supriyo Mukherjee because there's a cost for sorting the list as well

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

    if there is some cost associated with each activity and our goal is earn max cost by performing maximum activities,,,, will greedy work if yes how?

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

      Lavkush Tiwari no you’ll need dynamic programming for that. Subscribe here if you’re interested in AI

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

    tnx a lot

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

    can u plzz tell how to write an algo of all these greedy methods

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

      If you are looking for an implementation of the problems in the video, you can refer the link given in the description.
      Here it is for this problem: www.geeksforgeeks.org/greedy-algorithms-set-1-activity-selection-problem/

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

    Because of subtitles we cannot see the algorithm written...and even you are not telling that algorithm each and every letter

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

      You can disable subtitles in the video (the button beside the button of quality/speed of the video)

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

    we could have choosen A4 instead of A5. i am not clear why we choose A5

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

      because finishing time of A5 is less than A4 and we have already sorted them according to their finishing time so A5 comes before A4.

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

      if we choose A4 then we won't be able to select other activities after it which would result in less activities done.

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

    what is stl sort

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

      STL sort is not any kind of sort. STL is a modern format of C++ where sorting is an in built function

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

    nice

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

    Please use mic

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

    in Activity Selection Problem code why you write i=j in program

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

      because the present activity becomes the previous activity for the next activity

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

    sexy explaination ....

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

    Not understand

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

    Worst audio with unclear explanation. I'm talking about whole playlist, this is genuine critisism

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

    Arey algorithm thodi ratni hoti hai. What is the intuition behind sorting by finish time and not start time? You know what's better than these GFG videos? Just copy gfg article text convert text to speech

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

    360p

  • @mubinladhani8467
    @mubinladhani8467 11 місяців тому

    👍

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

    You don't discuss the proof of correctness, not fair!!

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

    So basically this guy didnt explain why end time is taken for the sorting ordering. disliked.

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

      So basically there are three ways to do the problem,but only one optimal way.
      1) Let say you sort the array based on start time array ,Then there is this problem that the first activity you selected may take a huge amount of time but by then you would have done better if you would have opt for the remaining activities instead of this first one.(one way to justify the falseness).
      .............................................................................................................................................................................................................................................................................
      2) Now let say you didn't sort the array in any way and keep taking everything that comes in your way.(This is the worst thing anyone would do,I hope you know it well).
      .............................................................................................................................................................................................................................................................................
      3)Now comes your actual question i(why sort the based on the finish time right?) , So the obvious yet not obvious explanation is that when you sort activities based on end-times then as we choose those with min end-time ,we end up doing a lot of activities as we get across the first things first!!(just think about it)

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

    please give a proper c code implementation for better understanding ,,
    complete code in c

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

    I can't see the example....Ur subtitle work as an obstacle

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

      Thanks for the feedback. We will keep this in mind for further videos.
      Meanwhile, you can turn off the subtitles for the video wherever necessary.

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

      Ooo ok..thnq..

  • @storiesofmykind
    @storiesofmykind 5 місяців тому

    Not at all helpful

  • @vijayKumar-xq1wu
    @vijayKumar-xq1wu 4 роки тому

    sir but if we select a3,a2,a4 instead of a3,a4,a5,a6 then more work would be done

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

      Hi Vijay, I had the same doubt but It's not about Maximum weight Its about having Max no of activity.
      - a3,a2,a4 = 3 activity
      - a3,a2,a5,a6 = 4 activity.(winner)
      Also, the max weight in this example will be a1,a6

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

    "lets summarize these steps into a code"
    That's not how English works..

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

    content is good, video quality and accent aren't!

    • @zippy.gaurav
      @zippy.gaurav 4 роки тому

      Nobody cares about the accent.