Question

Given the following recursive function: unsigned int mymod( unsigned int a, unsigned int b ) {...

Given the following recursive function:

unsigned int mymod( unsigned int a, unsigned int b )
{
  if( a < b ) return a;
  return mymod( b - a, b );
}

the function call mymod(5, 2) will

Select one:

a. execute infinitely and terminates with an error.

b. execute until some if-condition matches.

c. not compile, it will generate a compilation error.

d. return the value: 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1


a) a. execute infinitely and terminates with an error.

Add a comment
Know the answer?
Add Answer to:
Given the following recursive function: unsigned int mymod( unsigned int a, unsigned int b ) {...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q5. [5 marks] Consider the following recursive function: int Test (int number) //Line 1 //Line 2...

    Q5. [5 marks] Consider the following recursive function: int Test (int number) //Line 1 //Line 2 if (number == 0) //Line 3 return number; //Line 4 else //Line 5 return (number + Test (number - 1)); //Line 6 //Line 7 a. Identify the base case. b. Identify the general case. c. If Test (0) is a valid call, what is its value? If not, explain why. d. If Test (5) is a valid call, what is its value? If not,...

  • This is for C in Linux: Problem 1: Given the following recursive function: void recursiveFunction( int...

    This is for C in Linux: Problem 1: Given the following recursive function: void recursiveFunction( int m ) printf("%d", m); if( m <= 0 ) return; if( n + 2 == 0 ) recursiveFunction( m - 1); else recursiveFunction( m - 2); What is the output when the following functions are called with these parameters? recursiveFunction( 5 ); recursiveFunction( 10 ); recursiveFunction( 0);

  • 5.43 (10 pts) What does the following program do? #include <stdio.h> 3 unsigned int mystery Cuns...

    5.43 (10 pts) What does the following program do? #include <stdio.h> 3 unsigned int mystery Cuns igned int a, unsigned int b): // function prototype 5 int main(void) printf("%s". "Enter two positive integers: unsigned int x: I/ first integer unsigned int y: // second integer scanf("Su%u". &x, &y); "); 12 13 14 15 II Parameter b must be a positive integer 16 to prevent infinite recursion 7 unsigned int mystery Cuns igned int a, unsigned int b) 18 printf("The result...

  • Given the recursive method: public int someValue(List<Integer> A) { if (A.size() > 0) { int v...

    Given the recursive method: public int someValue(List<Integer> A) { if (A.size() > 0) { int v = A.get(0); A.remove(0); return v + someValue(A); } else return 0; } What value does the method return if A contains 1 2 3 4 5? a. 0 b. 5 c. 10 d. 15

  • 2. Consider the function george (int n) computed by the following recursive C++ code. int george ...

    2. Consider the function george (int n) computed by the following recursive C++ code. int george (int n) assert (n >= 0) if (n < 2) return 1; else return 2*george ((n+1)/2)+2*george (n/2)+2 george((n-1)/2)+2*george (n/2-1); (c) Design a memoization algorithm to compute george(n) for any given n. You do not have to write C++ code. This algorithm should be much faster than the dynamic programming algorithm. What is its time complexity? 2. Consider the function george (int n) computed by...

  • *Program is in C* Write a recursive function to compute a^b for integers a and b....

    *Program is in C* Write a recursive function to compute a^b for integers a and b. For the recursive use the following equality a^b = a^b - 1 * a and a^0 = 1. What does the following recursive function do? int mystery(int a, int b) {if (b == 1) return (a); else return (a + mystery(a, b - 1));}

  • (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int...

    (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1. The terSearch search function, unlike the binary search, must consider two dividing points int d1 = l + (r - l)/3 int d2 = d1 + (r - l)/3 For the first call of your recursive search function...

  • PROBLEM 4: Consider the recursive C++ function below: void foo(unsigned int n) {     if(n==0)        ...

    PROBLEM 4: Consider the recursive C++ function below: void foo(unsigned int n) {     if(n==0)         cout << "tick" << endl;     else {         foo(n-1);         foo(n-1);         foo(n-1);     } } 4.A: Complete the following table indicating how many “ticks” are printed for various parameters n. Unenforceable rule: derive your answers “by hand” -- not simply by writing a program calling the function. n number of ticks printed when foo(n) is called 0 1 2 3 4 4.B:...

  • Let’s work together to develop a call tree for the execution of the following recursive method....

    Let’s work together to develop a call tree for the execution of the following recursive method. (The method allows us to recursively generate the nth integer in the Fibonacci sequence, although you don’t need to be familiar with that sequence to understand this problem.) public static int fib(int n) { if (n == 0 || n == 1) { return 1; } else { int prev1 = fib(n - 2); int prev2 = fib(n - 1); return prev1 + prev2;...

  • And also when recursive(5). Consider the following funtion int recursive(int n) f The assembly code equivalent...

    And also when recursive(5). Consider the following funtion int recursive(int n) f The assembly code equivalent of the above function is: recursive push %ebp mov %esp,%ebp push %ebx sub $0x14,%esp cmpl $0x1,0x8(%ebp) je L1 cmpl $0x2,0x8(%ebp) jne L2 L1 mov 0x8 (%ebp),%eax jmp L3 L2 mov 0x8 (%ebp),%eax sub $0x1,%eax mov %eax, (%esp call recursive mov %eax,%ebx mov ox8(%ebp),%eax sub $0x2,%eax mov %eax, (%esp call recursive imul %ebx,%eax L3 add $0x14,%esp pop %ebx pop %ebp ret

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT