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

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 พ.ย. 2024

ความคิดเห็น • 93

  • @JaDoggCoder
    @JaDoggCoder 4 ปีที่แล้ว +56

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

  • @sumeetmohapatra1211
    @sumeetmohapatra1211 6 ปีที่แล้ว +3

    I think for(j=i+1;j

  • @danielshahverdi7053
    @danielshahverdi7053 6 หลายเดือนก่อน +1

    Like always! Simple and understanding❤

  • @rajghorpade717
    @rajghorpade717 27 วันที่ผ่านมา

    Best explication

  • @rinasinha5299
    @rinasinha5299 3 ปีที่แล้ว +1

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

  • @NishantKumar-pt5zj
    @NishantKumar-pt5zj 7 ปีที่แล้ว +8

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

  • @sadeghkhosravi
    @sadeghkhosravi ปีที่แล้ว

    very nice and clearly!! Thank you😊💕

  • @abhineelnandi9552
    @abhineelnandi9552 3 ปีที่แล้ว +3

    Very good explanation , concise and to the point.

  • @shivateja7574
    @shivateja7574 4 ปีที่แล้ว

    Excellent explanation

  • @harshpenga
    @harshpenga ปีที่แล้ว

    @geekforgeek
    update kr lo Bhai .. way of teaching

  • @shuvbhowmickbestin
    @shuvbhowmickbestin 3 ปีที่แล้ว

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

  • @shahdahmedsamer5441
    @shahdahmedsamer5441 ปีที่แล้ว

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

  • @mdarshhamza8661
    @mdarshhamza8661 6 หลายเดือนก่อน

    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

  • @sadeceaka
    @sadeceaka ปีที่แล้ว

    Thanks from Turkey :))

  • @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).

  • @techielovekid6121
    @techielovekid6121 2 ปีที่แล้ว

    Doubt clear thanks buddy

  • @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

  • @souravganguly5680
    @souravganguly5680 6 ปีที่แล้ว +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.

  • @ShortsAddict382
    @ShortsAddict382 2 ปีที่แล้ว

    nice explanation

  • @estherwanjiru6001
    @estherwanjiru6001 4 หลายเดือนก่อน

    Thank you sir

  • @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 8 หลายเดือนก่อน +1

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

  • @Bakasta170
    @Bakasta170 4 ปีที่แล้ว +1

    its very good, keep doing good work!!

  • @dikshantyadav1110
    @dikshantyadav1110 6 ปีที่แล้ว +3

    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 ปีที่แล้ว +3

      use any method of sorting

    • @harshvardhanyadav8949
      @harshvardhanyadav8949 3 ปีที่แล้ว

      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

  • @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

  • @hemanthkumarmaddi4505
    @hemanthkumarmaddi4505 7 ปีที่แล้ว +1

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

  • @ritiksarda
    @ritiksarda 4 ปีที่แล้ว

    Please increase the volume of the video

  • @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

  • @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).

  • @abhishekshah8554
    @abhishekshah8554 7 ปีที่แล้ว +1

    short and sweet

  • @santoshreddy9963
    @santoshreddy9963 3 ปีที่แล้ว

    Anyone please explain why we are always considering first time.

  • @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.

  • @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.

  • @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.

  • @KrishnasagarSubhedarpage
    @KrishnasagarSubhedarpage 7 ปีที่แล้ว

    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?

  • @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
    ??

  • @lavkushtiwari2799
    @lavkushtiwari2799 7 ปีที่แล้ว

    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

  • @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 6 ปีที่แล้ว

      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.

  • @crickettalkwithsupriyo3828
    @crickettalkwithsupriyo3828 7 ปีที่แล้ว

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

    • @NilankoHalder
      @NilankoHalder 7 ปีที่แล้ว

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

  • @JatinGupta
    @JatinGupta 5 ปีที่แล้ว

    Please use mic

  • @vikashroy1461
    @vikashroy1461 6 ปีที่แล้ว +1

    Can you explain me about activity compare.

  • @navtejinderbrar3764
    @navtejinderbrar3764 7 ปีที่แล้ว

    are we using merge sort technique?

    • @alieser7770
      @alieser7770 6 ปีที่แล้ว +1

      who gives a damn but probably quicksort

  • @shadownut5802
    @shadownut5802 ปีที่แล้ว

    thanks

  • @sandeshs299
    @sandeshs299 ปีที่แล้ว

    Not understand

  • @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/

  • @anilcelik7937
    @anilcelik7937 6 ปีที่แล้ว

    excellent, thank you

  • @abrahamalemseged8436
    @abrahamalemseged8436 4 ปีที่แล้ว

    tnx a lot

  • @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

  • @tejadayana8300
    @tejadayana8300 ปีที่แล้ว

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

  • @vishalmishra1937
    @vishalmishra1937 6 ปีที่แล้ว

    what is stl sort

    • @souravganguly5680
      @souravganguly5680 6 ปีที่แล้ว

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

  • @blindprogrammer
    @blindprogrammer 5 ปีที่แล้ว

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

  • @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..

  • @amanaswal11
    @amanaswal11 4 ปีที่แล้ว

    nice

  • @jahidulhaqueshanto264
    @jahidulhaqueshanto264 6 ปีที่แล้ว

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

  • @mubinladhani8467
    @mubinladhani8467 ปีที่แล้ว

    👍

  • @vaibhavtale318
    @vaibhavtale318 2 ปีที่แล้ว

    sexy explaination ....

  • @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

  • @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)

  • @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

  • @storiesofmykind
    @storiesofmykind 7 หลายเดือนก่อน

    Not at all helpful

  • @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 5 ปีที่แล้ว

      Nobody cares about the accent.