Guest User

Untitled

a guest
Jun 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #I think this code can be used for size of list which is perfect square
  2. import math
  3. def jump_search(l,target):
  4. jump = int(math.sqrt(len(l)))-1
  5. for i in range(0,len(l)+1,jump):
  6. if l[i] == target:
  7. target_position = i
  8. elif l[i]>target:
  9. last_position = i-jump
  10. current_position = i
  11. break
  12. for j in range(last_position, current_position):
  13. if l[j] == target:
  14. position = j
  15. break
  16. else:
  17. position = -1
  18. return position
Add Comment
Please, Sign In to add comment