Hey all!
This week's algorithm design and analysis will be on optimizing the total amount of points on your homework or work. Given a list of problems of length j, can I figure out which problem(s) to do within a total time T?
For example, each problem is worth Pj points but takes Tj time to do. If I have T hours before my homework is due, which problems should I do to maximize the number of points I receive?
Design an algorithm that achieves this goal and then analyze the time/space complexity of your solution.
[Challenge] Homework optimization
Page 1 of 111 Replies - 4906 Views - Last Post: 23 February 2014 - 01:08 PM
Replies To: [Challenge] Homework optimization
#2
Re: [Challenge] Homework optimization
Posted 13 February 2014 - 06:41 PM
Then when you're done, put all of your completed work into your knapsack and take it to school...
#3
Re: [Challenge] Homework optimization
Posted 13 February 2014 - 07:20 PM
I thought that you got the most amount of homework done by posting all the questions to DIC and various other programming forums and just wait for the results to roll in. O(n) because you can find minions to parallelize the posting operation, have the solutions come in parallel, but you'll have to sequentially assemble the results which will be O(n).
#4
Re: [Challenge] Homework optimization
Posted 13 February 2014 - 07:27 PM
I think searching on stackoverflow is also O(n), but with better constants.
#5
Re: [Challenge] Homework optimization
Posted 14 February 2014 - 02:06 PM
The O(1) method
Spoiler
#6
Re: [Challenge] Homework optimization
Posted 14 February 2014 - 02:12 PM
What's the time complexity of nerd()?
#7
Re: [Challenge] Homework optimization
Posted 14 February 2014 - 03:37 PM
Doesn't matter to me, as it done asynchronously and I can be doing other tasks.
#9
Re: [Challenge] Homework optimization
Posted 15 February 2014 - 08:01 AM
TwoOfDiamonds, no the greedy approach does not work. Let me give you a counterexample.
P1 = 30, T1 = 30, P1/T1 = 1
P2 = 20, T2 = 10, P2/T2 = 2
P3 = 5, T3 = 10, P3/T3 = 1/2
If I have T = 30, then this algorithm will first grab P2/T2 for 20 points and then be stuck with P3/T3 as the only one it can do in the remaining time for a total of 25 points.
If, instead, I did JUST problem 1, I would have 30 points.
P1 = 30, T1 = 30, P1/T1 = 1
P2 = 20, T2 = 10, P2/T2 = 2
P3 = 5, T3 = 10, P3/T3 = 1/2
If I have T = 30, then this algorithm will first grab P2/T2 for 20 points and then be stuck with P3/T3 as the only one it can do in the remaining time for a total of 25 points.
If, instead, I did JUST problem 1, I would have 30 points.
#11
Re: [Challenge] Homework optimization
Posted 17 February 2014 - 11:41 PM
Neat solution mac! Thanks for sharing!
#12
Re: [Challenge] Homework optimization
Posted 23 February 2014 - 01:08 PM
When I solved this problem, I used a dynamic programming technique where I had a 2D table which had j columns (one per task) and T rows. I then used the recursive function M(j, t) which gives the max of the first j sub problems. You can define the recursion as:
Translating this recursion into dynamic programming is simple, but the algorithm is O(j*t) in both time and space.
M(j,t) = {0, if j = 0
max(M(j-1, t), Pj + M(j-1, t-Tj), if Tj < t
M(j-1, t), else
}
Translating this recursion into dynamic programming is simple, but the algorithm is O(j*t) in both time and space.
Page 1 of 1

New Topic/Question
Reply



MultiQuote







|