Question: Which XXX condition generates the following output?Not found #include #include #include using namespace std; int BinarySearch ( vector numberList, int element, int lowVal, int highVal

Which XXX condition generates the following output?Not found
#include
#include
#include
using namespace std;
int BinarySearch(vector numberList, int element, int lowVal, int highVal){
int midVal;
if (XXX){
midVal =(highVal + lowVal)/2;
if (numberList.at(midVal)== element){
return midVal;
}
else if (numberList.at(midVal)> element){
return BinarySearch(numberList, element, lowVal, midVal -1);
}
else {
return BinarySearch(numberList, element, midVal +1, highVal);
}
}
else {
return -1;
}
}
int main(){
vector numberList(0);
int element =20;
int matchPos;
for (int i =0; i <=10; ++i){
numberList.push_back(i);
}
matchPos = BinarySearch(numberList, element, 0, numberList.size()-1);
if (matchPos >=0){
cout << "Found at position "<< matchPos <<"."<< endl;
}
else {
cout << "Not found. "<< endl;
}
return 0;
}
Which XXX condition generates the following output?Not found
#include
#include
#include
using namespace std;
int BinarySearch(vector numberList, int element, int lowVal, int highVal){
int midVal;
if (XXX){
midVal =(highVal + lowVal)/2;
if (numberList.at(midVal)== element){
return midVal;
}
else if (numberList.at(midVal)> element){
return BinarySearch(numberList, element, lowVal, midVal -1);
}
else {
return BinarySearch(numberList, element, midVal +1, highVal);
}
}
else {
return -1;
}
}
int main(){
vector numberList(0);
int element =20;
int matchPos;
for (int i =0; i <=10; ++i){
numberList.push_back(i);
}
matchPos = BinarySearch(numberList, element, 0, numberList.size()-1);
if (matchPos >=0){
cout << "Found at position "<< matchPos <<"."<< endl;
}
else {
cout << "Not found. "<< endl;
}
return 0;
}
lowVal = highVal
lowVal + highVal ==0
lowVal == highVal
lowVal <= highVal

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!