Explore BrainMass

Algorithm - El Camino de Santiago Sample Question

Need help with attached questions.

Algorithm - El Camino de Santiago Sample Question


Solution Preview

Please see the attachment.

Problem #1
I use a greedy algorithm to find the list of albergues specifying where you will rest.
The basic idea is, for each day, you should walk as far as possible, until you can rest at th albergue but can not rest at th albergue. In another word, if you rest at th albergue, your walking distance of this day is less than or equal to miles; if you rest at th albergue, then you have walk more than miles a day. This is not allowed from the condition. The pseudo code is as follows.
Input: array X[1...n] and d, where X[1]=0 is the start point, X[k] is the distance between the kth albergue and the start point, d is the maximum distance you can walk for one day.
Output: array Y[1...m], where Y[k] is the index of albergue where you take a rest on the kth day.
FindAlbergues(X, d)
1. Set k=1; // Start point at X[1]
2. Set t=1; // Start day is day 1
3. while (k<=n) { // Go through ...

Solution Summary

Sample solution for algorithm question. El Camino de Santiago sample questions are examined.