Question

1.        A. Write a recursive brute force algorithm that calculates an. B. Write the java code...

1.       

A. Write a recursive brute force algorithm that calculates an.

B. Write the java code that does the calculation.

C. What is the recurrence relation for the number of multiplications?

D. What is the efficiency class of the algorithm?

Homework Answers

Answer #1

A)Here is the brute force algorithm

  1. let the function be power(a,n)
  2. if n==0 return 1
  3. else return a*power(a,n-1)

B)Here is the java code

C)

Recurrence relation is :

power(a,n)=n*power(a,n-1)

D)

efficency class of the algorithm is O(n).

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
Write a C++ recursive function that counts the number of nodes in a singly linked list....
Write a C++ recursive function that counts the number of nodes in a singly linked list. (a) Test your function using different singly linked lists. Include your code. (b) Write a recurrence relation that represents your algorithm. (c) Solve the recurrence relation using the iterating or recursive tree method to obtain the running time of the algorithm in Big-O notation.
a. Design a non-recursive algorithm for computing an (discussed in the class). What is the basic...
a. Design a non-recursive algorithm for computing an (discussed in the class). What is the basic operation? How many times is the algorithm’s basic operation executed? b. Using an = a*an-1 (discussed in the class) to design a recursive algorithm for computing an . What is the basic operation? Set up and solve a recurrence relation for the number of times that algorithm's basic operation is executed. c. Using an = a*(a(n-1)/2) 2 (n is odd integer) and an =...
Consider the following recursive algorithm Algorithm S(n) if n==1 return 1 else return S(n-1) + n*n*n...
Consider the following recursive algorithm Algorithm S(n) if n==1 return 1 else return S(n-1) + n*n*n 1)What does this algorithm compute? 2) Set up and solve a recurrence relation for the number of times the algorithm's basic operation is executed. 3) How does this algorithm compare with the non-recusive algorithm for computing thius function in terms of time efficeincy and space effeciency?
Consider the following recursive algorithm. Algorithm Test (T[0..n − 1]) //Input: An array T[0..n − 1]...
Consider the following recursive algorithm. Algorithm Test (T[0..n − 1]) //Input: An array T[0..n − 1] of real numbers if n = 1 return T[0] else temp ← Test (T[0..n − 2]) if temp ≥ T[n − 1] return temp else return T[n − 1] a. What does this algorithm compute? b. Set up a recurrence relation for the algorithm’s basic operation count and solve it.
Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent...
Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent subprogram in Java for the EBNF rule. Please summit your source code and a screen shot of the parsing of the following examples. do { if ( number % 2 == 0 ) even ++; number=number+1; } while (number <= 10)
1. a. Write the Java code to fill a Java array of ints of size 100...
1. a. Write the Java code to fill a Java array of ints of size 100 with the value -1. b. Write the Java code to create an ArrayList of Strings, and add the Strings "Just", "Do", "It!" to it.
Below is C code and Python code for an algorithm. C code: void foo( int n,...
Below is C code and Python code for an algorithm. C code: void foo( int n, int A, int B, int C ) { if( n==1 ) { printf("%d to %d\n",A,B); return; } foo( n-1, A, C, B ); printf("%d to %d\n",A,B); foo( n-1, B, C, A ); Python code: def foo(n , A, B, C): if n==1: print A, "to", B return foo(n-1, A, C, B) print A, "to", B foo(n-1, B, C, A) Let Hn be the number...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x)...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x) { switch (x) { case 1: break; case 2: break; case 0: break; default: break; case 4: break; } } Select one: a)Each case section must end with a break statement. b)The case label 0 must precede case label 1. c)There is nothing wrong with the Java code. d)The default label must be the last label in the switch statement. e)The variable x does...
Write an application in Java which includes an algorithm that takes an array of any size,...
Write an application in Java which includes an algorithm that takes an array of any size, selects the high and low integer from the array of integers with each pass and builds a new array of integers by inserting the high and low selection with each pass. Your output should show the original array of integers and the output of each pass on a new line. Note: You can assume all integers are positive, but your code must work for...
Java programming 1) Which among the choices is the following Java expression equivalent to? !((b !=...
Java programming 1) Which among the choices is the following Java expression equivalent to? !((b != 0) || (c <= 5)) Select one: a)       (b != 0) && (c <= 5) b)       (b == 0) && (c > 5) c)       !((b <> 0) && (c <= 5)) d)       (! (b = 0)) && (! (c > 5)) e)       (b == 0) && (c <= 5) 2) The scope of a variable is an important feature in Java, the following variable...