Repository where I mostly put random python scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
610 B

'''
Sends array, searchValue, arraySize as input.
Returns the index of the searchValue in the array
'''
def jumpSearch(arr , x , n ):
# Finding block size to be jumped
step = math.sqrt(n)
# Finding the element
prev = 0
while arr[int(min(step, n)-1)] < x:
prev = step
step += math.sqrt(n)
if prev >= n:
return -1
# Doing a linear search
while arr[int(prev)] < x:
prev += 1
if prev == min(step, n):
return -1
if arr[int(prev)] == x:
return prev
return -1