C Code Use the following C code and answer the questions Dem
C++ Code
Use the following C++ code and answer the questions. Demonstrate each step of this searching algorithm when search (0, 8, 10) is executed.Solution
#include <iostream>
 using namespace std;
int a[] = {2,5,8,10,12,15,20,23};
 char search(int low,int high,int item)
 {
    int mid = (low+high)/2;
    cout<<\"low =\"<<low<<\"\\thigh =\"<<high<<\"\\tmid =\"<<mid<<\" a[mid] =\"<<a[mid]<<\"\ \";
    int size = 8;
    if(item > a[mid] && mid ==size-1)
    {
        return \'F\';
    }
    else if(item < a[mid] && mid ==0)
    {
        return \'F\';
    }
    else if(item > a[mid])
    {
        low = mid;
        return search(low,high,item);
    }
    else if(item < a[mid])
    {
        high = mid;
        return search(low,high,item);
    }
    else
    {
        return \'T\';
       
    }
 }
 int main()
 {
    cout<<search(0,8,10);
    return 0;
 }
output:
Explaination of output:
10>8 ,low = mid . search(2,4,10)
10 =10

