navroze
navroze

Reputation: 35

Check correctness of the algorithm for minimum number of jumps in an array

I have an algorithm that is based on a problem where you need to find the minimum number of jumps to reach the end of the array.This problem was asked in geeks for geeks and they do not have a linear time algorithm in my case the algorithm is in linear time but for which test case would my Algorithm fail?.The link for the problem

Link:-http://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-array/

Input: arr[] = {1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9}

Upvotes: 0

Views: 125

Answers (1)

bezmax
bezmax

Reputation: 26142

Yes, this algorithm does not work. Example:

arr[] = {5,2,1,1,1,1,1}

Your algorithm would see 5, then see max number 2, then go to 1 1 1 1. That is: 5,2,1,1,1,1 = 6 jumps.

While the optimal result is: 5 -> 1 (second from end) -> 1 = 3 jumps

Upvotes: 1

Related Questions