11 Replies - 4906 Views - Last Post: 23 February 2014 - 01:08 PM

#1 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

[Challenge] Homework optimization

Post icon  Posted 13 February 2014 - 03:06 PM

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.

Is This A Good Question/Topic? 3
  • +

Replies To: [Challenge] Homework optimization

#2 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 12350
  • View blog
  • Posts: 20,984
  • Joined: 19-March 11

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...
Was This Post Helpful? 1
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

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). :)
Was This Post Helpful? 1
  • +
  • -

#4 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 12350
  • View blog
  • Posts: 20,984
  • Joined: 19-March 11

Re: [Challenge] Homework optimization

Posted 13 February 2014 - 07:27 PM

I think searching on stackoverflow is also O(n), but with better constants.
Was This Post Helpful? 1
  • +
  • -

#5 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: [Challenge] Homework optimization

Posted 14 February 2014 - 02:06 PM

The O(1) method
Spoiler

Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 12350
  • View blog
  • Posts: 20,984
  • Joined: 19-March 11

Re: [Challenge] Homework optimization

Posted 14 February 2014 - 02:12 PM

What's the time complexity of nerd()?
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

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.
Was This Post Helpful? 1
  • +
  • -

#8 TwoOfDiamonds   User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 272
  • Joined: 27-July 12

Re: [Challenge] Homework optimization

Posted 15 February 2014 - 07:45 AM

Spoiler

Was This Post Helpful? 1
  • +
  • -

#9 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

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.
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: [Challenge] Homework optimization

Posted 15 February 2014 - 09:11 AM

Spoiler

Was This Post Helpful? 1
  • +
  • -

#11 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

Re: [Challenge] Homework optimization

Posted 17 February 2014 - 11:41 PM

Neat solution mac! Thanks for sharing!
Was This Post Helpful? 0
  • +
  • -

#12 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

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:

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.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1