L13. Fractional Knapsack Algorithm

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

КОМЕНТАРІ • 118

  • @shwetathakare1556
    @shwetathakare1556 7 місяців тому +34

    Understood. Striver ,String series please its much needed!!!!

  • @sandeepxt99
    @sandeepxt99 8 місяців тому +10

    I study DSA in many courses but trust me such a way, you teach never found.l❤

  • @unfamousgaayak4838
    @unfamousgaayak4838 7 місяців тому +18

    Hello bro , subscribed to ur channel today .. started late but one day even i have hopes that i will understand complex dsa problems. I want to switch from service based to product based .. the kind of work u r doing for us is truely inspirational. Keep inspiring us ❤❤

    • @SibiRanganathL
      @SibiRanganathL 4 місяці тому

      keep rocking bruh
      One day you ill become @famousgaayak4838

  • @Dsa_kabaap
    @Dsa_kabaap 8 місяців тому +58

    Sir please start making videos on strings and stacks

    • @arunbhagat8023
      @arunbhagat8023 8 місяців тому +1

      Recursion and Backtracking please

    • @shreyanshsrivastav6773
      @shreyanshsrivastav6773 8 місяців тому +3

      @@arunbhagat8023 There is already a playlist on recursion by striver

    • @arunbhagat8023
      @arunbhagat8023 8 місяців тому

      @@shreyanshsrivastav6773 that is basic

    • @arunbhagat8023
      @arunbhagat8023 8 місяців тому

      @@shreyanshsrivastav6773 it is basic

    • @AmandeepSingh-rd6ql
      @AmandeepSingh-rd6ql 7 місяців тому

      ​@@arunbhagat8023 please share the joint you are smoking 🚬

  • @guneeshvats46
    @guneeshvats46 6 місяців тому +11

    Striver why did you remove the Stacks and Queues Videos from your channel ?????

  • @shreyasrk6465
    @shreyasrk6465 3 місяці тому +2

    we can easily solve this with the help of comparator just add all these values into a vector then just sort using a comparator on the basis of its unit weight then just for loop from 0-n-1 add weights if its larger then just add a else statement where you perform the knapsack fraction condition simple and best🥰🥰

  • @priyanshpatro4548
    @priyanshpatro4548 6 місяців тому +7

    why did you remove the stack and queues playlist aadha kiya tha

  • @guptaujjwal
    @guptaujjwal 8 місяців тому +15

    Strings and stack queues after this please!

  • @Ayush-777
    @Ayush-777 8 місяців тому +6

    A2Z DSA course , I am a new learner and found that some videos are coming soon, and in step 2, only counting frequencies of array elements and other videos are not uploaded. Please guide me on what we have to do here.

    • @lifehustlers164
      @lifehustlers164 7 місяців тому +2

      bhai leave them basics must have been clear and now move to arrays directly.

  • @summasumma
    @summasumma 8 місяців тому +2

    Nice! Thanks for clear explanation. May i know which pen/tablet and app you are using for this teaching ?

  • @52nevil36
    @52nevil36 8 місяців тому +3

    Heart from india.. watching from 🇨🇦

  • @resha7601
    @resha7601 6 місяців тому +1

    Hey Striver! Will there be a SDE SHEET CHALLENGE 2024? Love the work you do for the community

  • @karthikeyanv4128
    @karthikeyanv4128 6 місяців тому +14

    hey striver why u did stack and queue playlist as private

    • @guneeshvats46
      @guneeshvats46 6 місяців тому +2

      Yes last night it was uploaded and now its not there what happened?

  • @iamnoob7593
    @iamnoob7593 7 місяців тому +1

    Completed , Thanks a ton striver

  • @codewithsanjeev4236
    @codewithsanjeev4236 7 місяців тому +4

    Please bring string series

  • @viewer1821
    @viewer1821 6 місяців тому +7

    stack series coming soon!!
    saw striver's leetcode profile he solved stack problems 😁

  • @_thingsthatmatter
    @_thingsthatmatter 7 місяців тому +2

    sir i love your vidoes u make dsa look very easy. i did linked list from you and understood all the concepts but stack and queue is something I am facing a lot of challenge with. can you please after this playlist complete the stack and queue playlist.

  • @sushmi6400
    @sushmi6400 6 місяців тому +3

    Where is stacks playlist...?striver...

  • @arunbhagat8023
    @arunbhagat8023 8 місяців тому +7

    Recursion Backtracking Strings and Stack Next Please...

  • @deveshsharma-u2l
    @deveshsharma-u2l 6 місяців тому +2

    did it myself ,thanks for building up my logic uptill now heres the code i did:class Solution {
    static class Pair implements Comparable{
    double ratio;
    int index;
    public Pair(int index,double ratio){
    this.index=index;
    this.ratio=ratio;
    }
    @Override
    public int compareTo(Pair p1){
    return Double.compare(p1.ratio,this.ratio);
    }
    }
    // Function to get the maximum total value in the knapsack.
    double fractionalKnapsack(int w, Item arr[], int n) {
    PriorityQueuepq=new PriorityQueue();
    for(int i=0;i

  • @riyan-g-4
    @riyan-g-4 6 місяців тому +8

    Hey striver, please make the Stack Queue series public. I was in the middle of a video lol

    • @Deepakkumar-pm2kt
      @Deepakkumar-pm2kt 6 місяців тому

      why he did private bro????

    • @ASHUTOSHSHARMA-us6hd
      @ASHUTOSHSHARMA-us6hd 5 місяців тому +2

      paise mangega na abhi toh, tuf+ pe krega mujhe lgta hai

    • @abhimanyuambastha2595
      @abhimanyuambastha2595 4 місяці тому

      @@ASHUTOSHSHARMA-us6hd Its back up!!

    • @manansanghani1032
      @manansanghani1032 2 місяці тому +1

      @@ASHUTOSHSHARMA-us6hd fr bro , now i understand why he never upload strings on yt , bhai ko bhi course bechna h

  • @nikhilpatidar9338
    @nikhilpatidar9338 7 місяців тому +2

    Sir having a doubt not of this que
    I come through this problem many time as I try to run the code it executes and gives correct output for some case but sometimes submiting the code gives error at same test case with different output
    What actually is going on and how to handle it

    • @adnanbhat_
      @adnanbhat_ 6 місяців тому +1

      use Double in the comparitor function
      so what happens is assum we have val1 = 10 , 7 and val 2 = 10 , 6
      so it compares 10/7 , 10/6 becz in int type they both are 1 so it return 10/7 which is wrong but using double solves it .

  • @kaichang8186
    @kaichang8186 4 місяці тому

    understood, thanks for the perfect explanation

  • @mmbmmbmmb
    @mmbmmbmmb 6 місяців тому +8

    sir apne private kyu krdi stack best playlist thi

  • @vivekbhore5722
    @vivekbhore5722 3 місяці тому +1

    done n dusted 🔥

  • @souvikbasak4396
    @souvikbasak4396 7 місяців тому +3

    Striver a request, could you kindly provide a shorter playlist version for the binary search playlist as you said you would and as you have done for graphs and dp , as we have very less time for placements.

  • @ashishpradhan6250
    @ashishpradhan6250 6 місяців тому +1

    this playlist also done... thanks

  • @hat_awesome21
    @hat_awesome21 7 місяців тому +3

    Sir ppz start stack and queue and strings 😢

  • @somith16
    @somith16 8 місяців тому +3

    Recursion playlist needed

  • @thenews8464
    @thenews8464 8 місяців тому +1

    Why you made your screen small please zoom it although I cant concentrate seriously looking at you😅

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

    Understood,Greate explanation.

  • @thewarriorzzzz
    @thewarriorzzzz 6 місяців тому +1

    Stack and Queue series kyun udd gayi?????

  • @anu6811
    @anu6811 8 місяців тому +1

    understood ♥...... next heaps playlist please🥺!!!!

  • @AbhishekSharma-26
    @AbhishekSharma-26 8 місяців тому +2

    please upload the videos of string

  • @k-nl4kj
    @k-nl4kj 6 місяців тому

    done with greedy it was freaking awesome

  • @yaswanthgummadi7318
    @yaswanthgummadi7318 7 місяців тому +1

    Bro can you please solve the problem "STRONG PASSWORD CHECKER" in leetcode question no.420. And make a video on it.

  • @gnanaphanideep6398
    @gnanaphanideep6398 3 місяці тому

    love u bro💓

  • @Gg69696
    @Gg69696 7 місяців тому +1

    is this the last video for greedy algorithms ??

  • @b.s.n.murthy8798
    @b.s.n.murthy8798 7 днів тому

    #User function Template for python3
    class Solution:
    # Function to get the maximum total value in the knapsack.
    def fractionalknapsack(self, val, wt, capacity):
    #code here
    fin=[]
    res=[]
    for i in range(len(val)):
    t=(val[i],wt[i],val[i]/wt[i])
    fin.append(t)
    fin = sorted(fin, reverse=True, key = lambda x:x[2])
    value = 0
    weight=0
    i=0
    while icapacity:
    value+= (capacity-weight)*fin[i][2]
    break
    value+=fin[i][0]
    weight+=fin[i][1]
    i+=1

    return value
    #{
    # Driver Code Starts
    #Position this line where user code will be pasted.
    if __name__ == '__main__':
    test_cases = int(input())
    for _ in range(test_cases):
    # Read values array
    values = list(map(int, input().strip().split()))
    # Read weights array
    weights = list(map(int, input().strip().split()))
    # Read the knapsack capacity
    W = int(input().strip())
    ob = Solution()
    print("%.6f" % ob.fractionalknapsack(values, weights, W))
    print("~")
    # } Driver Code Ends
    Done my own

  • @niranjanvs6599
    @niranjanvs6599 8 місяців тому +1

    I need Strings and Recursion videos

  • @woebegonetv
    @woebegonetv 8 місяців тому +2

    Segment Tree videos plz

  • @ishanmoykhede9484
    @ishanmoykhede9484 6 місяців тому +1

    broo where did your stack and queue playlist gone 🥲

  • @itz_pratap.007
    @itz_pratap.007 Місяць тому

    Is it greedy approach

  • @mayankprakash9651
    @mayankprakash9651 7 місяців тому

    Which notepad application are you using?

  • @rahulagrawal3611
    @rahulagrawal3611 7 місяців тому

    Striver bhai.. Plz add search bar in our website. Any problem I need to separately search in google tuf.. then in youtube tuf for video… tuf is my first preference for any dsa…

  • @its-itish
    @its-itish 4 місяці тому

    Thank You!..

  • @Deepakkumar-pm2kt
    @Deepakkumar-pm2kt 6 місяців тому +1

    bro public the stack and queue playlist again plss

  • @sano9633
    @sano9633 8 місяців тому +1

    can anyone tell me why Unauthorised showing again and again after i login from my gmail account

  • @45vinitthakkar56
    @45vinitthakkar56 7 місяців тому +2

    Stacks Queues plzzzzzz

  • @shravankumarsambaraju4219
    @shravankumarsambaraju4219 7 місяців тому

    can you please let me know the app that you are using for writing notes while explaining

  • @subhamchatterjee9695
    @subhamchatterjee9695 7 місяців тому

    brother pls upload the videos of string and stack queue

  • @Sharath_Codm
    @Sharath_Codm 6 місяців тому +1

    Start Doing on Strings please sir

  • @AnchitaPanjeta
    @AnchitaPanjeta 7 місяців тому +1

    strings after this please

  • @thoughtsofkrishna8963
    @thoughtsofkrishna8963 7 місяців тому +1

    Waiting for strings playlist

  • @user-rdr1712
    @user-rdr1712 5 місяців тому

    Series completed 😄

  • @karthik-varma-1579
    @karthik-varma-1579 3 місяці тому +3

    Undertstood but java Comparator is new to me

  • @ChaitanyaDugyani
    @ChaitanyaDugyani 7 місяців тому

    please upload video on java collections

  • @sonalipsadwibei2508
    @sonalipsadwibei2508 7 місяців тому +1

    Please sir upload on string

  • @shreerangaraju1013
    @shreerangaraju1013 7 місяців тому

    Two City Scheduling Please

  • @dhirisalasaisankar4338
    @dhirisalasaisankar4338 7 місяців тому

    Striver bro do video on Huffman coding

  • @Umesh-sk7km
    @Umesh-sk7km 8 місяців тому +1

    understood

  • @sandeepxt99
    @sandeepxt99 8 місяців тому +1

    ❤❤❤❤

  • @watch2-grow
    @watch2-grow 5 місяців тому

    Understood

  • @52nevil36
    @52nevil36 8 місяців тому +1

    First comment.. love from 🇨🇦

  • @divyareddy7622
    @divyareddy7622 7 місяців тому

    @takeUforward bhaiya pleasee give the codes too! THANKS A LOT

  • @guru-lu5vn
    @guru-lu5vn 7 місяців тому +1

    OPTIMAL SOLUTION $$
    class Solution {
    public:
    static bool comp(Item a, Item b){
    double r1 = (double) a.value/a.weight;
    double r2 = (double) b.value/b.weight;
    return r1>r2;
    }
    // Function to get the maximum total value in the knapsack.
    double fractionalKnapsack(int w, Item arr[], int n) {
    // Your code here
    double totalval=0;
    sort(arr,arr+n,comp);
    for(int i=0;i

  • @abromioitis
    @abromioitis 7 місяців тому +2

    vote for System Design 👇👇👇👇

  • @keshavsharma-fk1hb
    @keshavsharma-fk1hb 7 місяців тому

    Please upload string videos

  • @storm19019
    @storm19019 7 місяців тому

    Stack means lifo and queue means fifo naa

  • @storm19019
    @storm19019 7 місяців тому

    We are the Zeta alpha and none other than sorcher ones

  • @jalal-eddinelhachmi35
    @jalal-eddinelhachmi35 7 місяців тому

    What is the name of the app he use?

  • @zyzzbrah9429
    @zyzzbrah9429 8 місяців тому +1

    can anyone paste complete cpp code here

  • @storm19019
    @storm19019 7 місяців тому

    Take this

  • @cp65143
    @cp65143 7 місяців тому +1

    Greedy: I am here to make profit not to enjoy my life😂

  • @vighneshmudaliar3306
    @vighneshmudaliar3306 8 місяців тому +4

    ye toh sach h ki bhagwan h

  • @devprasad8767
    @devprasad8767 8 місяців тому +1

    Hi

  • @storm19019
    @storm19019 7 місяців тому

    Who who who who who who

  • @SamsIt-hi9gf
    @SamsIt-hi9gf 7 місяців тому

    class Solution {
    public:
    // Function to get the maximum total value in the knapsack.
    double fractionalKnapsack(int w, Item arr[], int n) {
    typedef pairpfi;
    priority_queuepq;
    for(int i = 0;i0&&pq.size()>0){
    auto it = pq.top();
    pq.pop();
    double vl = it.second.first;
    double wt = it.second.second;
    if(wt

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

    us

  • @storm19019
    @storm19019 7 місяців тому

    Look sandeep maheshwari greatest incentive ever than u

  • @storm19019
    @storm19019 7 місяців тому

    U r trolled by me and my brother

  • @storm19019
    @storm19019 7 місяців тому

    Baccho ka dsa

  • @storm19019
    @storm19019 7 місяців тому

    Who this rubbish sir

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @SibiRanganathL
    @SibiRanganathL 4 місяці тому

    understood

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @abhinanda7049
    @abhinanda7049 2 дні тому

    understood

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +1

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +2

    Strings and stack queues after this please!

  • @parassingh3877
    @parassingh3877 8 місяців тому +10

    Strings and stack queues after this please!