Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge

Name: Anonymous 2008-04-28 23:45

The challenge is to produce an algorithm to solve the Subset-Sum Problem in your language of choice.  To make it somewhat interesting try to make it as efficient as possible and do not copy an existing algorithm but come up with one yourself.

Bonus Points:  Make the algorithm run in polynomial time.

Name: Anonymous 2008-05-01 23:46

proc subset-sum(Set input)
  Set subsets := powerset(input)
  foreach (subsets as current_subset)
     if sum(current_subset) = 0
        return true
  return false
end

proc sum(Set input)
   sum := 0
   foreach (input.elements as current_element)
      sum := sum + current_element
   return sum
end


O(n log n)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List