C++ Code: github.com/striver79/SDESheet/blob/main/fractionalKnapsackC%2B%2B Java Code: github.com/striver79/SDESheet/blob/main/fractionalKnapsackJava Instagram for live sessions: Striver_79
Grand Salute to your Effort... Even with a lot of difficulty you are making videos for us,........... Hats off to you brother....... This proves why you are in this position.........
For some reason when we try to execute the code in gfg , the editor throws this error related to sort "error: invalid use of non-static member function"
what if I want all the items in the bag? and just want to break the weight to be able to put all of them.Is it possible in fractional knapsack or do I need to do other algorithm?, please answer I need this for my research 🥺
I have a simple doubt that if we take 10 thrice and 20 once then we can get profit as (60*3) + (100*1) = 280 which is more than 240 then why are we not considering it?
Replace the item array with array list of item And secondly Don't write arrays.sort change it to Collections.sort probably after this the code will work
HELP ME WITH THIS CODE WHY ITS NOT COMPILING bool comp(Item a,Item b) { double x = (double)(a.value) / (double)a.weight; double y = (double)(b.value) / (double)b.weight; return x > y; } double fractionalKnapsack(int W, Item arr[], int n) { sort(arr,arr+n,comp); double ans=0; double tw=0; for(int i=0;i
C++ Code: github.com/striver79/SDESheet/blob/main/fractionalKnapsackC%2B%2B
Java Code: github.com/striver79/SDESheet/blob/main/fractionalKnapsackJava
Instagram for live sessions: Striver_79
Big brother u r just a living example of --- "Take break but don't Quit ".......👍🔥🔥🔥
Grand Salute to your Effort... Even with a lot of difficulty you are making videos for us,........... Hats off to you brother....... This proves why you are in this position.........
Welcome Back Bro , You are A Fighter
:) thanks mate
If u are watching this in 2023 of after write
static bool comp(.....){. }. ✌🏻
Striver you're a legend you are saviour. You're my favourite.
Am i dreaming 😂 He is really back!!!
Yesss🔥
in ur words : Raj Bhaiya u are doing extremely well ❤️
Sir can you make a video on how to represent project Infront of interviewers what point Should we keep in our presentation?
Striver is back❤️
You are an inspiration!
UNDERSTOOD... !!!
Thanks striver for the video... :)
For some reason when we try to execute the code in gfg , the editor throws this error related to sort "error: invalid use of non-static member function"
use the static keyword before bool in the comparator function defination.
write the comparator function outside the solution class (its just another approach)
Your videos are always the best on TH-cam ♥️ no comparison ✨💯♥️
Great Explanation.
Great Explanation bhaiya....👏
I will literally pay you to finish videos on the placement series!
I missed your videos so much bhya ♥️ I hope you will be fine super soon💎✨
Hlw Bhaiya.I think in the 47th line will be.....findvalue += arr[i].value * ( (double)remain/(double)arr[i].weight ).Take love bhaiya
Thank you for bringing such good content, really appreciate it.
c++ at 11:09
Thankyou for making this video bro you video are very help full for all of us
Superb , Darun ❤
Waiting for your recovery and this amazing series video..God bless you.
how do we know that values are uniform and we can apply greedy rather than going for recursive solution ?
Thankyou for putting so much effort☺️☺️
Thank you bro for such a good explanation !
Welcome back !!
u r dng a great job brother
Thanks mate
what if I want all the items in the bag? and just want to break the weight to be able to put all of them.Is it possible in fractional knapsack or do I need to do other algorithm?, please answer I need this for my research 🥺
Salute to your dedication bhaiya
Please continue this playlist
Bhaiya what is dynamic programming with profile
Dynamic Programming suna hun but ye suna nai hun aaj tk me th :|
@@takeUforward I saw it a codeforces editoria(Div 1). Searched on the web, but still not much info there too.
Thank you brother❤
why sorting required that too in descending i tried without sorting test cases failing even if i descnding weights only can you pls tell why failing
why we used r1>r2 in the comp function?
Welcome back ❤️
Hey @takeyouforward wonot the array.value in end in final answer wonot be typecasted to double
First e comment kore ni then video dekhe nebo!
I know that Raj knows Bengali ❤️
Hahhahah
yes, he knows, aar jana uchit o, as he is from kolkata, and also from JGEC ❤️❤️,
Yeah coz he stays in my locality.
Welcome back Sir ⭐ and take care
Disclaimer - No Guy was harmed in making this video :p.
PS: Great Explanation! :)
Thanks! 😃
Very Nice Work
I have a simple doubt that if we take 10 thrice and 20 once then we can get profit as (60*3) + (100*1) = 280 which is more than 240 then why are we not considering it?
We need to put only one item of one type
Understood 💯💯💯
Great explaination
in the comparator function if it will return true that means we do not have to swap or it will swap??? please reply anyone..
Internally it does
@@takeUforward no i am asking if the comparator function condition is satisfied that it will sort or not???
Is Activity selection problem video is not uploaded?
class itemComparator implements Comparator{
@Override
public int compare(int a, int b){
double r1 = (double)(a.value)/(double)(a.weight);
double r2 = (double)(b.value)/(double)(b.weight);
if(r1 < r2) return 1;
else if (r1 > r2) return -1;
else return 0;
}
}
/*
Item arr[] = { new Item(10, 60),new Item(20, 100),new Item(30, 120) };
*/
Can you explain this step of Fractional Knapsack (step by step )
understood bhaiya
understood 💓
Love from JGEC.
where can i get this DSA sheet?
Understood.
1st view 😍 ✨ ♥, waiting for long time for your videos, how are you bhya, all well ??
Getting better every day..
I understood it!
Welcome Back Brother
Please take time and recover fully and then work Plss
Welcome back!
Just awesome ❤️❤️
How to solve fractional knapsack in linear time?
Understood🙃
Wow BRO, U r back!
Understood!
Brilliant thanks
god lvl explanation
You are the best
understood
Bro java code is giving wrong answer 😌😌😌😌😌😌
Replace the item array with array list of item
And secondly
Don't write arrays.sort change it to Collections.sort probably after this the code will work
nice video
Comeback Bolte
:)
The entire code :-
#include
using namespace std;
struct Item{
int value;
int weight;
};
bool comp(Item a, Item b) {
double r1 = (double)a.value / (double)a.weight;//first item
double r2 = (double)b.value / (double)b.weight;//second item
return r1 > r2;
}
// function to return fractionalweights
double fractionalKnapsack(int W, Item arr[], int n)
{
// Your code here
sort(arr, arr + n, comp);
int curWeight = 0;
double finalvalue = 0.0;
for (int i = 0; i < n; i++) {
if (curWeight + arr[i].weight
Thank you brother
hello bhaiya Yo masst
yo yo
bro you dont give the entire code
Is your health good?
Yeah neck movements are improving...
@@takeUforward take care bro!
Do we need to tell the brute force to the interviewer for this kind of problems ?
nice
I don't think so you should be uploading videos. Please please please 🥺 take care of your health first.
Got too bored sleeping on the bed to be honest.
😍
HELP ME WITH THIS CODE WHY ITS NOT COMPILING
bool comp(Item a,Item b)
{
double x = (double)(a.value) / (double)a.weight;
double y = (double)(b.value) / (double)b.weight;
return x > y;
}
double fractionalKnapsack(int W, Item arr[], int n)
{
sort(arr,arr+n,comp);
double ans=0;
double tw=0;
for(int i=0;i