sak1b

O(N)

Nov 18th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. my_list = [-106, 222,222,106,74,66,195,627,731,750,586,874,599,878,759,807]
  2.  
  3. print(len(my_list)) # list er lenght jodi hoy 5 -> money 5, 10
  4.  
  5. #5 -> money 5
  6. #10 -> money 10
  7. #100000000 -> money 100000000
  8. #3 -> money 3
  9. #X -> money X
  10. #N -> money N <======== O(N)
  11.  
  12.  
  13.  
  14. #money/time/space = resource ^
  15.  
  16. target = -106
  17. found = False #flag
  18.  
  19. money = 0
  20.  
  21. for item in my_list:
  22. money = money + 1
  23. if item == target:
  24. found = True
  25. break
  26.  
  27. print('money:',money)
  28.  
  29. if found == True:
  30. print('Found the target: ',target)
  31. else:
  32. print('Did not find the target')
Advertisement
Add Comment
Please, Sign In to add comment