Question: Is my answer for this code in question 1 correct did I make my control flow graph correctly? Consider the following code 1 int binsearch

Is my answer for this code in question 1 correct did I make my control flow graph correctly?
Consider the following code
1 int binsearch (int X , int V [], int n )
2{
3 int low , high , mid , i ;
4 low =0;
5 high = n -1;
6
7 for ( i =0; i high ; i ++)
8{
9 if ( V[ i ]> V [ i +1])
10 return -2;
11}
12
13 while ( low = high )
14{
15 mid =( low + high )/2;
16 if ( X V [ mid ])
17 high = mid -1;
18 else
19 if ( X > V [ mid ])
20 low = mid +1;
21 else
22 return mid ;
23}
24 return -1;
25}
This code takes as input a sorted array V of size n, and an integer X, if X exists in the array it will rDraw a Control flow graph for binsearch().
1
Initialize: binsearch(int X, int V[], int n)
2
low =0,
high =n-1
y : Investigateeturn the index of X, else it will return -1.
 Is my answer for this code in question 1 correct did

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 Databases Questions!