Welcome to Westonci.ca, your ultimate destination for finding answers to a wide range of questions from experts. Get detailed and accurate answers to your questions from a community of experts on our comprehensive Q&A platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.
Sagot :
Step number 3 is to compare the number 33 with the given number. Below is code in C++ where you can check it.
C++ code
#include<iostream>
using namespace std;
int main()
{
- //Initialize list and variables
int step,n,half,first,last,ext;
int list[] = {1,2,3,4,10,11,16,25,32,33,45,47,51,69,75};
first = 0;
last = 14;
ext = 0;
step = 0;
cout<< "Entry number to find: ";
cin>> n;
- //Binary Search
while (first <= last and ext == 0)
{
- //submit comparison
half = (first+last)/2;
step=step+1;
cout << "Step: " << step;
cout << " Compare the number " << list[half] << " with " << n <<endl;
if (n == list[half])
ext = 1;
if (n < list[half])
last=half-1;
if (n > list[half])
first=half+1;
}
}
To learn more about Binary search see: https://brainly.com/question/21475482
#SPJ4
Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. We hope our answers were useful. Return anytime for more information and answers to any other questions you have. Westonci.ca is committed to providing accurate answers. Come back soon for more trustworthy information.