Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions