Write a program to find the number of comparisons using binary Search and the se
ID: 3618391 • Letter: W
Question
Write a program to find the number of comparisons using binary Search and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. Use a random number generator to fill list. Use any sorting algorithm to sort list. Search list for some items as follows: Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.) Use the binary search algorithm to search the list, switching to a sequential search when the size of the search list reduces to less than 15. (Use the sequential search algorithm for a sorted list.) Print the number of comparisons for Steps c.i and c.ii. If the item is found in the list, then print its position.Explanation / Answer
#include #include #include int fermatTest (int n) { int a, result, i; a = rand() % n; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.