Skip to content

Commit 94a40ac

Browse files
author
Dhiraj
committed
jump search in python2
1 parent 6442ae2 commit 94a40ac

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Search/JumpSearch/jumpSearch.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import math
2+
def jump_search(arr,search):
3+
4+
j_block = len(arr)
5+
low = 0
6+
interval = int(math.sqrt(j_block))
7+
for i in range(0,j_block,interval):
8+
if arr[i] < search:
9+
low = i
10+
elif arr[i] == search:
11+
return i
12+
else:
13+
break # bigger number is found
14+
c=low
15+
for j in arr[low:]:
16+
if j==search:
17+
return c
18+
c+=1
19+
return "Not found"
20+
21+
arr = [ 0, 1, 1, 2, 3, 5, 8, 13, 21,34, 55, 89, 144, 233, 377, 610 ]
22+
23+
search_block = 55
24+
res = jump_search(arr, search_block)
25+
print("Number" , search_block, "is at index" ,"%.0f"%res)

0 commit comments

Comments
 (0)