Write a C++ program to find the number of comparisons using the binary Search an
ID: 3636099 • Letter: W
Question
Write a C++ program to find the number of comparisons using the binary Search and the sequential search algorithms 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. Alternatively, you can use the function insert0rd to initially insert all the elements in the list.
. Search list for some items as follows:
. Use the binary search algorithm to search the list. (you might 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 then 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
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.