Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5. Finally, implement a binary search, and count how many comparisons it took to find or not find the number:
- UNSORTED:
- 42 8469 6335 6503 9171 5726 1480 9361 6965 4467
- 5706 8148 3284 6829 9962 492 2996 1944 4828 5437
- 2395 4606 3903 154 293 2384 7423 8718 9720 9897
- 5448 1729 4773 1540 1870 9914 5670 6302 7037 9895
- 8706 3814 1326 337 7675 4665 5143 7712 8256 6869
- SORTED:
- 42 154 293 337 492 1326 1480 1540 1729 1870
- 1944 2384 2395 2996 3284 3814 3903 4467 4606 4665
- 4773 4828 5143 5437 5448 5670 5706 5726 6302 6335
- 6503 6829 6869 6965 7037 7423 7675 7712 8148 8256
- 8469 8706 8718 9171 9361 9720 9895 9897 9914 9962
- Enter a number to search for: 7037
- Comparing 5448 to 7037...
- Comparing 7712 to 7037...
- Comparing 6503 to 7037...
- Comparing 6965 to 7037...
- Comparing 7423 to 7037...
- Comparing 7037 to 7037...
- Found in 6 comparisons
- -----------------------------
- UNSORTED:
- 42 8469 6335 6503 9171 5726 1480 9361 6965 4467
- 5706 8148 3284 6829 9962 492 2996 1944 4828 5437
- 2395 4606 3903 154 293 2384 7423 8718 9720 9897
- 5448 1729 4773 1540 1870 9914 5670 6302 7037 9895
- 8706 3814 1326 337 7675 4665 5143 7712 8256 6869
- SORTED:
- 42 154 293 337 492 1326 1480 1540 1729 1870
- 1944 2384 2395 2996 3284 3814 3903 4467 4606 4665
- 4773 4828 5143 5437 5448 5670 5706 5726 6302 6335
- 6503 6829 6869 6965 7037 7423 7675 7712 8148 8256
- 8469 8706 8718 9171 9361 9720 9895 9897 9914 9962
- Enter a number to search for: 7000
- Comparing 5448 to 7000...
- Comparing 7712 to 7000...
- Comparing 6503 to 7000...
- Comparing 6965 to 7000...
- Comparing 7423 to 7000...
- Comparing 7037 to 7000...
- Not found in 6 comparisons
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement