diff --git a/sorting and basics/jump_search b/sorting and basics/jump_search new file mode 100644 index 0000000..f400883 --- /dev/null +++ b/sorting and basics/jump_search @@ -0,0 +1,19 @@ +import math + +def jmpFind( arr , x , n ): + step = math.sqrt(n) + prev = 0 + while arr[int(min(step, n)-1)] < x: + prev = step + step += math.sqrt(n) + if prev >= n: + return -1 + while arr[int(prev)] < x: + prev += 1 + + if prev == min(step, n): + return -1 #element not found + if arr[int(prev)] == x: + return prev + + return -1