I seem unable to understand Problem 2 in Problem Set 8: Dynamic Programming. I can't understand how why the entries 6.00 and 15.01 are selected and not others. Any help appreciated.
I managed to figure out what is expected but I cannot understand how cmpValue, cmpWork and cmpRatio can be used to find all those dictionary items which have an identical maximum value. For example in the provided file there are at least a dozen (didn't actually count the entries) having a maximum work value of 10.
The code in Problem 2 is not designed to find the optimal set, if that's your intention. (The Problem 4 code is for that). greedyAdvisor() will just return a set containing any of those with similar values
ditto - greedy can return different sets of subjects depending on how the subjects are ordered if there are multiple subjects with the same value, it will take the first one it gets to imo, the comparator functions serve multiple purposes in this exercise - roots an idea in your subconscious that there may be more than one way to define 'best' and that some 'bests' can be better than other 'bests' - it gets you familiar with (practical experience with) passing a function as an argument to another function - this is a functional programming concept - if you play around with it, it should give you an idea of the utility of being able to pass a function to another function - like being able to compare different concepts of 'best' without writing completely different sets of code. that is really cool.
Thanks
Join our real-time social learning platform and learn together with your friends!