jeudi 29 janvier 2015

Difficulty finding a recursive starting point for an algorithm


I am a student at university taking an analysis of algorithms class, and this dynamic programming problem has me stumped. I can't figure out how exactly I should define my recursive algorithm. The problem is best described by the following image:


Problem


where the goal is to open the least amount of lockers while still retrieving every tennis ball. Not every key has to be used. I also know that I should get a complexity of O(N(M^2)) We are given the following:



  • n : the number of lockers

  • m : the number of keys

  • t : the number of tennisballs

  • M[1..m] : an array of all key indexes, not necessarily sorted

  • T[1..t] : an array of all tennis ball indexes, not necessarily sorted


We are given the following hint:


Let d[i] be the minimum number of lockers that must be opened to gather all the tennis balls between the first locker and the locker that key i opens assuming that key i is used. Start your development of a dynamic programming algorithm by figuring out how to compute d[i] recursively and then compute d[i] bottom up. Once you have computed d[i] for all the keys you can choose from, how do you determine the final solution?


I am just having trouble getting started with finding a recursive solution for this. Any more hints would be appreciated. I would prefer some information or another hint that would point me in the right direction to an answer, if at all possible.





1 commentaire: