1 Assume the addition of the two functions public void recur

1. Assume the addition of the two functions:

public void recursiveDelete(int ky) {

// calls the private version

}

private Node recursiveDelete(int ky, Node n);

Write both functions.

2. Algorithm A has running time TA(n) = 106 + 104 × n + 105 × n2 and algorithm B has running time TB(n) = 3 × n3 , where n is the number of values the algorithms processes. Give the “big O” equations for the running times and state which algorithm is fastest for large n.

3. Algorithm C has running time TC(n) = O(n), algorithm D has running time TD(n) = O(log n), and algorithm E has running time TE(n) = O(sqrt(n)). Which algorithm is the fastest and which is the slowest for large n?

Solution

Q1.) Given question is not clear

Q2.) t(A(n)) = 105n2+104n+106 = O(n2)

t(B(n)) = 3n3 = O(n3)

It is clear, algo. A will be fastest for large value of n as algo. A has time complexity O(n2) while algo B has time complexity O(n3).

Q3.)

We know, O(logn)>O(sqrt(n)) > O(n) will be the order for fast execution.

Therefore, out of three algo. , D will be fastest as time complexity of D is O(logn) and C will be slowest as time complexity of C is O(n).

Hope it helps. Do give your feedback.

1. Assume the addition of the two functions: public void recursiveDelete(int ky) { // calls the private version } private Node recursiveDelete(int ky, Node n);

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site