Question

3. Determine the general result (in terms of n) of the following recursive function (4 pts.)...

3. Determine the general result (in terms of n) of the following recursive function (4 pts.)

              public static void func2(int n)

     {

        if(n == 1)

           System.out.println(“*”);

        else

        {

           for (int i = 1; i <= n; i++)

              System.out.print(“*”);

           System.out.println();

           func2(n-1);

                     }

              }

4. Does func2 above perform down or bottom up computation? ___________________ (2 pts.)

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

3)

public static void func2(int n)

     {

        if(n == 1)

           System.out.println(“*”);

        else

        {

           for (int i = 1; i <= n; i++)

              System.out.print(“*”);

           System.out.println();

           func2(n-1);

                     }

              }

For the above program it prints '*' in either case. So the output depends on 'n' value. It prints n '*'.

4)The above funcu2 is bottom up computation.

Add a comment
Know the answer?
Add Answer to:
3. Determine the general result (in terms of n) of the following recursive function (4 pts.)...
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
  • 1. Determine what the following function calls return for recursive function func below.     (4 pts.)...

    1. Determine what the following function calls return for recursive function func below.     (4 pts.)               public static int func(int n)      {         if(n == 1)            return 2;         else            return 2 + func(n-1);                      (a) func(1) = ________        (b) func(4) = ________ 2. Does func above perform top down or bottom up computation? ____________ (2 pts.)

  • Give a big-Oh characterization, in terms of n,of the running time for each of the following...

    Give a big-Oh characterization, in terms of n,of the running time for each of the following code segments (use the drop-down): - public void func1(int n) { A. @(1). for (int i = n; i > 0; i--) { System.out.println(i); B. follogn). for (int j = 0; j <i; j++) System.out.println(j); c.e(n). System.out.println("Goodbye!"); D.@(nlogn). E.e(n). F.ein). public void func2 (int n) { for (int m=1; m <= n; m++) { system.out.println (m); i = n; while (i >0){ system.out.println(i); i...

  • Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class...

    Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class Fibonacci { // Fib(N): N N = 0 or N = 1 // Fib(N-1) + Fib(N-2) N > 1 // For example, // Fib(0) = 0 // Fib(1) = 1 // Fib(2) = Fib(1) + Fib(0) = 1 + 0 = 1 // Fib(3) = Fib(2) + Fib(1) = Fib(2) + 1 = (Fib(1) + Fib(0)) + 1 = 1 + 0 + 1...

  • 7. Consider the following recursive function: package javaapplication293; public class JavaApplication293 public static void main Stringl...

    7. Consider the following recursive function: package javaapplication293; public class JavaApplication293 public static void main Stringl args) recFun(7) public static void recFun int u) if (-= 1 ) System.out. print("Stop! "); else System.out.print("Go "); recFun(u-1);

  • 3) Consider the following recursive method, what will be the output for the following method calls?...

    3) Consider the following recursive method, what will be the output for the following method calls? Explain. (25 pts.) public static void sample (int number) if (number < 0) { System.out.println( superwriteVertical (-number); System.out.println(number); superwriteVertical (number/ 10); else if (number 10) else ( System.out.print1n(number % 18); sample(-100); sample(50); sample(1024);

  • 17. For the following program, draw a stack to find the output. public class RecApp public...

    17. For the following program, draw a stack to find the output. public class RecApp public static void main(String[] args) System.out.println(Sum(7)); public static int Sum(int n) if (n < 1) return 5; else return n + Sum (n-2); Output: (13) Stack: (4%) Sum (_ ) Sum(_) Sum(_) Function Value Parameter Function Value Parameter Function Value Parameter Function Value Parameter Function Value Parameter Sum( ) 7 + Sum (5) Sum (7) Write the recursive equation (Tn)) for the run time of...

  • In each of the following questions, first use NetBeans IDE to run the code (if there...

    In each of the following questions, first use NetBeans IDE to run the code (if there is an error fix it) then take a screenshot of the output and paste it under (A). In (B), justify the output you obtained in (A). - 9. Given the following: public class WorkingSheet {     public static void main(String[] args) {        B myB = new B();        A myA = new B();        System.out.print(myB instanceof A);        System.out.print(myB instanceof C);        System.out.print(myA...

  • Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement...

    Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement some list functionalities on an ArrrayList of generic type using type parameters in method definition Our goal for this lab is to continue using the divide and conquer approach of splitting a list into its head and tail and keep recursing on the tail (which happens to be smaller). However, instead of trying the approach on a string (a list of characters) we would...

  • Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly...

    Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly below): //Create public class count public class Count {     public static void main(String args[])     {         int n = getInt("Please enter an integer value greater than or equal to 0");                System.out.println("Should count down to 1");         countDown(n);                System.out.println();         System.out.println("Should count up from 1");         countUp(n);     }            private static void countUp(int n)     {...

  • 1. Write a recursive function that computes the sum of all numbers from 1 to n,...

    1. Write a recursive function that computes the sum of all numbers from 1 to n, where n is given as parameter. Here is the method header: public static int sum (int n){...} 2. Write a recursive function that finds and returns the minimum value in an array, where the array and its size are given as parameters. Here is the method header: public static int minValue (int [] data, int size){...} 3. Write a recursive function that reverses the...

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