Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. 5. Finally, implement a binary search, and count how many comparisons it took to find or not find the number:
  2.  
  3. UNSORTED:
  4. 42 8469 6335 6503 9171 5726 1480 9361 6965 4467
  5. 5706 8148 3284 6829 9962 492 2996 1944 4828 5437
  6. 2395 4606 3903 154 293 2384 7423 8718 9720 9897
  7. 5448 1729 4773 1540 1870 9914 5670 6302 7037 9895
  8. 8706 3814 1326 337 7675 4665 5143 7712 8256 6869
  9. SORTED:
  10. 42 154 293 337 492 1326 1480 1540 1729 1870
  11. 1944 2384 2395 2996 3284 3814 3903 4467 4606 4665
  12. 4773 4828 5143 5437 5448 5670 5706 5726 6302 6335
  13. 6503 6829 6869 6965 7037 7423 7675 7712 8148 8256
  14. 8469 8706 8718 9171 9361 9720 9895 9897 9914 9962
  15. Enter a number to search for: 7037
  16. Comparing 5448 to 7037...
  17. Comparing 7712 to 7037...
  18. Comparing 6503 to 7037...
  19. Comparing 6965 to 7037...
  20. Comparing 7423 to 7037...
  21. Comparing 7037 to 7037...
  22. Found in 6 comparisons
  23.  
  24. -----------------------------
  25.  
  26. UNSORTED:
  27. 42 8469 6335 6503 9171 5726 1480 9361 6965 4467
  28. 5706 8148 3284 6829 9962 492 2996 1944 4828 5437
  29. 2395 4606 3903 154 293 2384 7423 8718 9720 9897
  30. 5448 1729 4773 1540 1870 9914 5670 6302 7037 9895
  31. 8706 3814 1326 337 7675 4665 5143 7712 8256 6869
  32. SORTED:
  33. 42 154 293 337 492 1326 1480 1540 1729 1870
  34. 1944 2384 2395 2996 3284 3814 3903 4467 4606 4665
  35. 4773 4828 5143 5437 5448 5670 5706 5726 6302 6335
  36. 6503 6829 6869 6965 7037 7423 7675 7712 8148 8256
  37. 8469 8706 8718 9171 9361 9720 9895 9897 9914 9962
  38. Enter a number to search for: 7000
  39. Comparing 5448 to 7000...
  40. Comparing 7712 to 7000...
  41. Comparing 6503 to 7000...
  42. Comparing 6965 to 7000...
  43. Comparing 7423 to 7000...
  44. Comparing 7037 to 7000...
  45. Not found in 6 comparisons
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement