Write a C++ program to find the number of comparisons using binarySearch and the
ID: 3634075 • Letter: W
Question
Write a C++ program to find the number of comparisons using binarySearch and the sequential search algorithm as follows:Suppose list is an array of 1000 elements.
a. Use a random number generator to fill list.
b. Use any sorting algorithm to sort list.
c. Search list for some items as follows:
i. Use the binary search algorithm to search the list
ii. Use the binary search algorithm to search list reduces to less then 15.
d. Print the number of comparisons for c.i and c.ii. If the item is found in the list, then print its position.
Suppose that L is a list is of length n and it is sorted using insertion sort. If L is already sorted in the reverse
order, show that the number of comparisons is (1/2) (n2 (squared) - n) and the number of item assignments is
(1/2) (n2 (squared) +3n) -2.
Explanation / Answer
#include #include #include int binarysearch(int list[], int end, int target, int &locn) { int first=0, mid, last=end; while(firstlist[mid]) first=mid+1; else if(targetRelated 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.