Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #I think this code can be used for size of list which is perfect square
- import math
- def jump_search(l,target):
- jump = int(math.sqrt(len(l)))-1
- for i in range(0,len(l)+1,jump):
- if l[i] == target:
- target_position = i
- elif l[i]>target:
- last_position = i-jump
- current_position = i
- break
- for j in range(last_position, current_position):
- if l[j] == target:
- position = j
- break
- else:
- position = -1
- return position
Add Comment
Please, Sign In to add comment