@above : call jumps(0,n-1);

On Sat, Jan 28, 2012 at 2:00 PM, atul anand <atul.87fri...@gmail.com> wrote:

> //code sketch .... based on greedy approach.
>
> jumps(int hop,int n)
> {
>        if(hop > n)
>        {
>              return;
>        }
>        if(hop==n)
>        {
>
>              //path found
>        }
>
>        for(i=hop ; i<n && i< hop+arr[hop] ; i++)
>        {
>              jumps( (i+arr[i])-1 , n);
>
>        }
> }
>
> little help required to find out path in minimum hop....please do modify
> code as required.
> thanks
>
>
> On Sat, Jan 28, 2012 at 12:48 AM, Don <dondod...@gmail.com> wrote:
>
>> At first I thought that I needed a special case to avoid zeros.
>> However, if you can move past a zero to a non-zero, that is always a
>> preferred move, and if not, a move to a location before the zero which
>> allows you to move past the zero is also better. If no such move
>> exists, there is no way to get to the end.
>> Don
>>
>> On Jan 27, 12:23 pm, sravanreddy001 <sravanreddy...@gmail.com> wrote:
>> > @Don:
>> >
>> > The solution looks good...
>> > I can see that the greedy choice property is holding.. and its optimal
>> > too...
>> >
>> > max (j+a[J]) maximizing is leading us to the farthest possible position,
>> >
>> > but.. in the beginning.. i thought.. this will have probs with 0's
>> > but.. couldn't come up an example, for which ur approach fail and
>> there's
>> > soultion for it.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to