4 Replies - 1453 Views - Last Post: 15 January 2010 - 10:07 AM

#1 racshot65   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-January 10

Algorithim to make a word from a hand of letters

Post icon  Posted 09 January 2010 - 01:05 PM

Hi,

I'm currently going through MIT's open courseware course on programming and I'm stuck on this assignment:

http://ocw.mit.edu/N...DBE/0/pset6.pdf

(Problem 3)

Basically you have a hand of letters and need to get the computer to make a word from those letters that scores the most points


I have the dictionary mapping the words to their point value but I don't know how I can make the computer pick the best word from my hand ?


Any Ideas ?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Algorithim to make a word from a hand of letters

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5612
  • View blog
  • Posts: 14,686
  • Joined: 18-April 07

Re: Algorithim to make a word from a hand of letters

Posted 09 January 2010 - 01:24 PM

Its the knapsack problem in disguise (the 0:1 variation sounds right). The knapsack size is the number of letters you have total. How many letters can you fit in it that also form a word to maximize their value. The idea is that you are going to run across all the combination of the letters possible, determining if it is a word, and if so also add up its value. A greedy algorithm would say grab as many letters and take the longest word, but that isn't necessarily going to be the most valuable. A shorter word may use more exotic letters and increase its value.

So look at the solution for the knapsack problem and you will see your solution to this data set. :)
Was This Post Helpful? 0
  • +
  • -

#3 racshot65   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-January 10

Re: Algorithim to make a word from a hand of letters

Posted 11 January 2010 - 02:55 PM

Hi,

Thanks for your reply.

Is a different but maybe less efficient way ?

The reason I say this is that based on the course calendar they don't teach the knapsack problem for another two lectures and this should be done before the next one
Was This Post Helpful? 0
  • +
  • -

#4 FXRev   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 13-January 10

Re: Algorithim to make a word from a hand of letters

Posted 15 January 2010 - 01:23 AM

Isn't the Knapsack problem a NP-Complete?
Was This Post Helpful? 0
  • +
  • -

#5 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Algorithim to make a word from a hand of letters

Posted 15 January 2010 - 10:07 AM

If you try to solve it "exactly". 0-1 or close enough can be done in polynomial time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1