Election Simulator

0 comments

Implement an Java ElectionSimulator class that can compute the minimum number of popular votes needed to win the Electoral College given the turnout during an election year.

1) ElectionSimulator(List<State> states)
Constructs a new ElectionSimulator for the given list of states.
2) Set<State> simulate()
Returns the set of states with the minimum number of popular votes needed to win the election.
See attached starter code
Design your recursive backtracking method to represent subproblems with two integer parameters: the current electoralVote threshold and the current index into the list of states. Then, solve the following optimization problem: “What is the set of states that minimizes the popular vote while satisfying the electoralVote threshold and using only states starting at the given index into the list of all states?”

Use the provided Arguments class to memoize (save) the solution to each subproblem by mapping the subproblem arguments to the set of states. If we’ve solved the subproblem before, then return the combination saved in the map.

  1. In the constructor, add a field to keep track of a new Map<Arguments, Set<State>>.
  2. In the recursive case, save the final solution to the current subproblem before returning the result.
  3. In the base case, if the solution to the current subproblem was saved earlier, return the saved solution.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}