Question
The following program is a binary search program in C. int search ( int key, int [] elemArray) { int bottom = 0; int top
The following program is a binary search program in C.
int search ( int key, int [] elemArray)
{
int bottom = 0;
int top = elemArray.length - 1;
int mid;
int result = -1;
while ( bottom <= top )
{
mid = (top + bottom) / 2;
if (elemArray [mid] == key)
{
result = mid;
return result;
} // if part
else
{
if (elemArray [mid] < key)
bottom = mid + 1;
else
top = mid - 1;
}
} //while loop
return result;
} // search
1. Identify the basic blocks and draw the flow graph.
2. Identify as many independent paths as possible with a minimum of three paths.
3. Of these paths, classify the paths as simple path and loop-free path.
4. Identify the definition, P-uses and C-uses. You could use the following format.
Statements | Def | P-Use | C-Use |
Statement 1 | X |
|
|
Statement 2 |
| X |
|
Statement n | X |
| X |
5. Identify the def-use associations of variables like bottom, top and mid.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started