Homework Help Global logo
  • Home
  • Coursework Help
  • Dissertation Help
  • Homework Help
  • My account
  • Order now
Order Now
Homework Help

Cs questions | Computer Science homework help

2 min read
Posted on 
August 22nd, 2022
Home Homework Help Cs questions | Computer Science homework help

1. Write a recursive algorithm to compute a+b, where a and b are nonnegative integers.

 

2. Let a be an array of integers. Write a recursive algorithm to compute the average of the elements of the array.

 

Solutions in which the sum is recursive (instead of the average) are worth fewer points. Note stopping case.

 

3. Ackerman’s function is defined recursively on the nonnegative integers as follows:

 

a(m, n) = n + 1 if m == 0

 

a(m, n) = a(m-1, 1) if m != 0, n == 0

 

a(m, n) = a(m-1, a(m, n-1)) if m != 0, n != 0

 

Using the above definition, show that a(2,2) equals 7.

 

4. If an array contains n elements, what is the maximum number of recursive calls made by the binary search algorithm?

 

5. The expression m % n yields the remainder of m upon division by n. Define the greatest common divisor (GCD) of two integers x and y by:

 

gcd(x,y) = y if ( y <= x && x % y == 0) if ( y <= x && x % y == 0)

 

gcd(x,y) = gcd(y, x) if (x < y )

 

gcd(x, y) = gcd(y, x % y) otherwise

 

Write a recursive method to compute gcd(x,y).

 

6. Define a generalized fibonacci sequence of f0 and f1 as the sequence gfib( f0, f1, 0), gfib(f0, f1, 1), gfib(f0, f1, 2), …, where

 

gfib(f0, f1, 0) = f0

 

gfib(f0, f1, 1) = f1

 

gfib(f0, f1, n) = gfib(f0, f1, n-1) + gfib(f0, f1, n-2) if n> 1

 

Write a recursive method to compute gfib(f0,f1,n).

 

7. Show how to transform the following iterative procedure into a recursive procedure. f(i) is a method returning a logical value based on the value of i, and g(i) is a method that returns a value with the same attributes as i. 605.202 Homework 3

 

void iter(int n)

 

{

 

int i;

 

i = n;

 

while ( f(i) == TRUE ) {

 

/* any group of statement that */

 

/* does not change the value of i */

 

i = g(i);

 

} // end while

 

} //end iter

 

8. Convert the following recursive program scheme into an iterative version that does not use a stack. f(n) is a method that returns TRUE or FALSE based on the value of n, and g(n) is a method that returns a value of the same type as n (without modifying n).

 

int rec(int n)

 

{

 

if ( f(n) == FALSE ) {

 

/* any group of statement that */

 

/* do not change the value of n */

 

return (rec(g(n)));

 

}//end if

 

}//end rec

Order an Essay Now & Get These Features For Free:

Turnitin Report

Formatting

Title Page

Citation

Outline

Place an Order
Share
Tweet
Share
Tweet
Calculate the price
Pages (275 words)
$0.00
Homework Help Global
Company
  • Coursework Help
  • Law Homework Help
  • Business Paper Help
  • Thesis Writing Help
Legal
  • Dissertation Help
  • Homework Help
  • Essay Writing
  • Custom Writing
How Our Service is Used:
Homework Help Global essays are NOT intended to be forwarded as finalized work as it is only strictly meant to be used for research and study purposes. Homework Help Global does not endorse or condone any type of plagiarism.
Subscribe
No Spam
© 2023 Homework Help Global. All rights reserved.
Homework Help Global will be listed as ‘Homework Help Global’ on your bank statement.