Question: Some JAVA question need help ?!!? 1. Complete Java program to produce the following output. // Example of Method Overloading class p3_4{ public static void

Some JAVA question need help ?!!?

1. Complete Java program to produce the following output.

// Example of Method Overloading

class p3_4{

public static void main(String args[]){ p3_4 obj=new p3_4(); obj.sum(10.5,10.5); obj.sum(20,20); } }

//output

21.0

40

2.Given the output stream A,B,C,D,E,F Write down the sequence of operations (Push for stack and Pop for unstack) which would produce the sequence C,B,D,E,F,A

3.What is the running time of each the method?

public int add100(int[] array) {

if (array.length < 100) {

return 0;

}

int sum = 0;

for (int i = 0; i < 100; i++) {

sum += array[i];

}

return sum;

}

public static void m4(int[] arr) {

for (int i=0; i

System.out.println(arr[i] * 10); }

for (int j=arr.length-1; j>=0; j--) {

System.out.println(arr[j] / 10); }

}

public static void m5(int[] arr) {

for (int i=0; i<15; i++) {

for (int j=0; j

System.out.println(Math.max(arr[i],

arr[j])); }}

}

4. Using big-O notation in terms of the parameter n, how much time does the following method take?

public static int mystery(int n) {

int count = 0;

int cur = 1;

while (cur < n) {

count++;

cur = cur * 2;

}

return cur;

}

5. Each of the below methods determine m, n without using Math.pow. Using big-O notation in terms of n, how much time does each take?

a.

int pow(int m, int n) {

int ret = 1;

for (int i = 0; i < n; i++) {

ret *= m;

}

return ret;

}

b.

int pow(int m, int n) {

int ret = 1;

int k = m;

int i = n;

while (i > 0) {

if (i % 2 == 1) ret *= k;

k *= k;

i /= 2;

}

return ret;

}

6. Why is binary search O(log2 N) ?

7.Create min heap tree for {7, 3, 5, 2, 4, 6}

8.When the root is removed from the above heap tree, how do we alter the tree? Create a new heap tree step by step.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!