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
Get step-by-step solutions from verified subject matter experts
