imtiazaasif

Linear Search Algorithm in python

Jun 10th, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. def linear_search(list,size,item):
  2.     for i in range(0, size):
  3.         if list[i] == item:
  4.             return i
  5.  
  6.     return -1
  7.  
  8. list = [5,6,7,8,9,10,11,12,31,41,47,85,77]
  9. size = len(list)
  10. item = 85
  11. index = linear_search(list,size,item)
  12. if (index == -1):
  13.     print('item not found ')
  14. else:
  15.     print('item found on index:',index+1)
Advertisement
Add Comment
Please, Sign In to add comment