Question

Draw a program flow graph for the function below int binsearch(int x,int v[],int n) { int...

Draw a program flow graph for the function below

int binsearch(int x,int v[],int n)
{
    int low,high,mid;

    low=0;
    high=n-1;

    while(low<high)
    {
        mid = ( low + high ) / 2;

        if( x < v[mid])
            high  = mid - 1;
        else if ( x > v[mid])
            low = mid + 1;
        else
            return mid;
    }
    return -1;
}

Homework Answers

Answer #1

The Program Flow Graph is provided below. In order to draw the Flow Graph the programming statements should be labelled as 1,2,3 etc. Please see the labelling of the statements and the Flow Graph below.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Determine the order of complexity for the following algorithm: function(int n) { int l, u, m;...
Determine the order of complexity for the following algorithm: function(int n) { int l, u, m;    l=0; u= n-1;    while (l<u) {        m= (l+u)/2;        if (a[m] < x) l= m+1;        else if (a[m] >x) u=m-1;            else return “found”    }    return (“not found”); }
Given the following function: int bar(int n) {     if( n < 0 )         return...
Given the following function: int bar(int n) {     if( n < 0 )         return -2;     else if (n <= 1)         return 2;     else       return (3 + bar(n-1) + bar(n-2)); } What is returned by bar (4)? Show all the steps
What does the following function compute? Give an analysis of its complexity int fun1 (int n)...
What does the following function compute? Give an analysis of its complexity int fun1 (int n) { if (n == 0)     return 1; else      return fun1(n-1) + fun1(n-1); }
1) Create a flowchart for the program below and Trace the program below with input of...
1) Create a flowchart for the program below and Trace the program below with input of 3 and then again with input of 5. #include <iostream> using namespace std; int Fall(int x, int m) { int Xm = 1, i=x; while(i>=x-m+1) { Xm = Xm*i; i=i-1; } return Xm; } int Delta(int x, int m) { int ans = 0; ans = Fall(x+1,m); ans = ans - Fall(x,m); return ans; } void main() { int x = 0, m =...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i];...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i]; } return (double)sum/n; } Rewrite the function to eliminate the array subscripting (a[i]), using pointer arithmatic instead. Write a program that reads a line of input and checks if it is a palindrome (ignoring spaces) Write a program that takes the name of a file as a command line argument, and prints the contents of the file (similar to the linux 'cat' program). Write...
Assume that the functions CS303 and UMKC have been defined as follows: int CS303(int n) {...
Assume that the functions CS303 and UMKC have been defined as follows: int CS303(int n) {      if (n == 0) {            return 1;      } else {            return UMKC(2, CS303(n - 1));      } } int UMKC(int n1, int n2) {      if (n1 == 0) {            return 0;      } else {            return n2 + UMKC(n1 - 1, n2);      } } What is the value of CS303(5)?
Give the output of the program using Call-By-Reference: int i, a[3]; void f (int x, int...
Give the output of the program using Call-By-Reference: int i, a[3]; void f (int x, int y){ x = (x*y) mod 3; y = y – x; } main(){ i = 0; a[0] = 1; a[1] = 2; a[2] = 0; f(i, a[i]); print(“%d %d %d %d\n”, i, a[0], a[1], a[2]); f(a[i], a[i]); print(“%d %d %d\n”, a[0], a[1], a[2]); }
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...
Assume that the functions CS303 and UMKC have been defined as follows: int CS303(int n) {...
Assume that the functions CS303 and UMKC have been defined as follows: int CS303(int n) { if (n <= 0) { return 1; } else { return UMKC(5, CS303(n - 5));      } } int UMKC(int n1, int n2) { if (n1 == 0) { return 0; } else { return n2 + UMKC(n1/5, n2);      } } What is the value of CS303(20)?
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...