1.1 KiB
1.1 KiB
title |
---|
Jump Search |
Jump Search
A jump search locates an item in a sorted array by jumping k items in the array and then verifies if the item wanted is between the previous jump and current jump.
Worst Case Complexity
O(√N)
How does it work ?
- Define the value of k, the number of jumps: The optimal jump size is √N where N is the length of the sorted array.
- Jump over the array elements by k everytime, checking the following condition
Array[i] < valueWanted < Array[i+k]
. - If the previous condition is true, then do a linear search between
Array[i]
andArray[i + k]
. - Return the position of the value if it is found in the array.
Code
To view examples of code implementation for this method, access this link below:
Jump Search - OpenGenus/cosmos