A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

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?

  • This Question is Closed
  1. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  4. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.