Essay Paper Assignment Help- Computer Science

Q1.Design an iterative algorithm to multiply odd integers. For example, if a given n is an odd integer, then the product is 1 * 3 * 5 * 7 * … * n; if n is an even integer, then the product is 1 * 3 * 5 * 7 * … * (n-1).

Q2.mplement your above iterative algorithm in Java with the following method header.

public static int oddProduct(int n)

Selected Answer:       

public class Main

{

    public static int oddProduct(int n)

    {

        int i = 1;

        int product = 1;

        if(i%2==0)

                   {

                       while(i<(n-1))

                       {

                       product*=i;

i+=2;

                       }

                   }

else{

                       while(i<(n))

                       {

                       product*=i;

i+=2;

                       }

                   }

    }

               public static void main(String[] args)

               {

                   int product;

                   int n = 9;

                   product= oddProduct(n);

System.out.println(product);

               }

}

Response Feedback:   

off by one

Q3.Design a recursive algorithm to multiply odd integers as specified in the previous question (Q1).

Q4.


Implement your above recursive algorithm in Java with the following method header:

public static int oddProduct(int n)

Selected Answer:       

public class Main

{

    public static int oddProduct(int n)

    {

        if (n == 1)

            return 1;

        else

            return n*oddProduct(n-2);

    }

               public static void main(String[] args)

               {

                   int product;

                   int n = 9;

                   product= oddProduct(n);

System.out.println(product);

               }

}

Response Feedback:   

What if n is even?

Q16.

Solve the recurrence relation using master’s theorem: T(n) = 9T(n/3) + n. Show all steps.

Q17.

Solve the recurrence relation: T(n) = 2T(n/2) + n, T(1) = 1, using the substitution method. Your answer must contain the following 3 parts. 1) detailed steps leading to the closed form; 2) the exact closed formula; 3) complexity in big O notation. Write an answer without steps will receive zero point. You can either use the Math editor in Blackboard, or write on a separate paper (don’t forget your name).

Q19.

You just realized that homework for CPS 340 is due in just 8 hours, yet you have not started. There are four questions in the homework, and each question with different points require certain number of hours to complete (see below). Use a brute-force strategy to maximize your points for the homework.

For your Problem:

hours left – 8

hours -[1,5,3,4]

points -[15,10,9,5]

Hours Left ->

0 1 2 3 4 5 6 7 8 -> hours left

000000000
01515151515151515
01515151515252525
01515152424252525
01515152424252529

so for [1,3,4] hour combination you can get the best points 29. questions -> [1,3,4]

For answers Contact us via proessaywiters@gmail.com

 

Leave a Reply