Find the number of leaps you need to take to find an element in an array using the jump search algorithm.
For example,
a=[ 2,5,6,9,12,14,15,16,17,19,31]
To find 16 with a jump step of 3, you follow, 2 -> 9 -> 15 -> 19 -> 17 -> 16
So, total number of jumps = 5
nb. to go forward, you take n-step jump; to go backwards, you jump only one step back.
- If the jump step is larger than the array size, u jump to the last element of the array.
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers9
Suggested Problems
-
22555 Solvers
-
Return unique values without sorting
1019 Solvers
-
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
400 Solvers
-
Matrix of almost all zeros, except for main diagonal
191 Solvers
-
420 Solvers
More from this Author174
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
In my opinion, Test 3 has an incorrect answer. It should be y_correct=0, because no jumps are required when the target is the first element in the list.
thanks william. it has been fixed
Asif, Can you explain test cases #4 and #5?
@Dyuman Joshi
If the jump step is larger than the array size, u jump to the last element of the array. (the problem definition is updated accordingly)