Question
int binsearch (int x, int v[], int n){ /* The input array v[] is assumed to be sorted in ascending order and n is the
int binsearch(int x, int v[], int n){ /* The input array v[] is assumed to be sorted in ascending order and n is the array size. You want to find the index of an element x in the array. If x is not found in the array, the routine is supposed to return -1. Answer the questions following the routine. */ a int low, high, mid; b low = 0; c high = n - 1; d while (low <= high) { e mid = (low + high)/2; f if (x < v[mid]) high = mid - 1; g else if (x > v[mid]) low = mid + 1; h else return mid; } i return -1; }
(a) Draw the control flow graph corresponding to the method binsearch. [3 marks]
(b) Describe the minimum set of test cases (or paths) through the control flow graph that is adequate for statement coverage but not edge/branch coverage. [3 marks]
(c) What additional test cases (if any) are required for branch coverage? [2 marks]
Question
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