Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 9 Online
OpenStudy (anonymous):

PS8#2: Greedy advisor. I've implemented a greedy advisor program. However, it's more brute force than elegance. I think the intuitive approach would be to do pre-processing and create sorted lists of tuples (where the tuple is (subject string, value/work/ratio). Then the program would simply read down the list. However, it seems that's not the approach the professor's wanted us to use as they specified that the function should take the comparator as an argument. Here's my implementation http://codepad.org/AjXZL6jD Did anyone come up with a simpler approach?

OpenStudy (anonymous):

to understand how greedyAdvisor works, getDictMax runs through the entire dictionary each time it's called and returns the maximum value using the comparator. It's pretty simply, it cycles through the dictionary, puts the dictionary entry into the comparator, and saves it if value the comparator says it great. http://codepad.org/g9HD6B3J

OpenStudy (anonymous):

i just went thru the dictionary and picked the best subject, amended maxWork then did it again and again ... til it was done here is mine with a small subject dictionary and a test function http://pastebin.com/HdZ9ssQM

OpenStudy (anonymous):

bwCA , my solution is similar to yours but I feel there is a better solution that just seeing if the given comparator is cmpWork , but I still can't find it :( http://pastebin.com/NbmEMHLn

OpenStudy (maitre_kaio):

To do this preprocessing, you would have to sort the whole subjects dictionary, right ? Complexity is O(n log n) in the best case, I think. With the solution proposed in the assignment, you just have to go through the whole list k times, k being the number of selected subjects, which is very small. Complexity is roughly O(kn). So the second solution is better when k is << n, which is the case.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
XShawtyX: Art, Short Writing Assignment: Imagining Landscapes
6 hours ago 2 Replies 0 Medals
XShawtyX: Chemistry, Help ud83dude4fud83cudffe
6 hours ago 13 Replies 1 Medal
kaelynw: tried a lil smt, the arm is off but i like the other stuff
17 hours ago 27 Replies 3 Medals
kaelynw: art igg
15 hours ago 14 Replies 2 Medals
XShawtyX: Art
3 days ago 6 Replies 0 Medals
Nina001: teach me how to draw or just tell me the basics
3 days ago 2 Replies 1 Medal
XShawtyX: We doing another drawing gimme ideas to add to this
3 days ago 9 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!