Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use java language to answer these qustions, and then test the code if it

ID: 3806238 • Letter: P

Question

Please use java language to answer these qustions, and then test the code if it need code (like qustion 2) to make suer the code work fine and type the answer please

1- Order the following functions by asymptotic growth rate. Explain your answer.

4n log n 210          2log n      

3n + 100 log n 4n 2n

n2 + 10n n3   n log n

2-Implement a method with signature transfer (S, T) that transfers all elements?

Please use java language to answer these qustions, and then test the code if it need code (like qustion 2) to make suer the code work fine and type the answer please

Explanation / Answer

PART 1:

The functions are arranged in increasing order by using the value of n in the functions. In general I will provide you a list that would help you for future arranging of the asymptotic functions.

0(1) < O(log n) < O(n) < O(nlog n) < O(n2) < O(n2logn) < O(n3) < O(2n)

The value of ‘log n’ is less ‘n’ and any number of addition in the value by ‘n’ will increase the value.

Following are the increasing order of the asymptotic growth rate:

1.   4nlog n, 210, 2log n

210 < 2log n < 4nlog n

2.   3n + 100log n, 4n, 2n

2n< 4n< 3n+100log n

3.   n2 + 10n, n3, nlog n

nlog n < n2 + 10n < n3

PART 2:

public static void signatureTransfer(Stack stack1, Stack stack2)
{
Object topOfStack = stack1.topOfStackEl();
//save the topOfStack
  
topOfStack = stack1.pop();
stack2.push(stack1.pop());
stack2.push(stack1.pop());
  
//push it back on to the stack
stack1.push(topOfStack);
stack1.push(stack2.pop());
stack1.push(stack2.pop());
  
//save the topOfStack
topOfStack = stack1.pop();
  
   // The bottom is left in Stack1
   stack2.push(stack1.pop());
stack2.push(topOfStack);
stack1.push(stack2.pop());
stack1.push(stack2.pop());
while(!stack1.isEmpty()){
stack2.push(stack1.pop());
}
System.out.println(stack1.toString());
System.out.println(stack2.toString());
}