Question

In: Computer Science

Question 14: Find the running time function, T(n), of the program below. def prob14(L): if len(L)...

Question 14: Find the running time function, T(n), of the program below.

def prob14(L):
    if len(L) <= 1:
        return 0
    output = 0
    for x in L:
        for y in L:
            output += x*y
    for x in L:
        output += x
    left = L[ 0 : len(L)//2 ]
    right = L[ len(L)//2 : len(L) ]
    return output + prob15(left) + prob15(right)

ANSWER:

T(n) = ...

***Big-O, Omega, Theta complexity of functions, Running time equations of iterative functions & recursive functions,  Substitution method & Master theorem

Please answer within these topics.***

Solutions

Expert Solution

HI ,

First of all ,

In above code prob15 is not defined .

If you have prob15 functionality or code please mention in comment. So i can write the function or add into this.

find the code with prob14 instead of prob15 in retiurn statement. -

def prob14(L):
    if len(L) <= 1:
        return 0
    output = 0
    for x in L:
        for y in L:
            output += x*y
    for x in L:
        output += x
    left = L[ 0 : len(L)//2 ]
    right = L[ len(L)//2 : len(L) ]
    return output + prob14(left) + prob14(right)

arr=[1,5,4,3,2]
print(prob14(arr))

output -

If you have anything , Feel free to mention in comment box,


Related Solutions

Problem 10 Write down the running time function, T(n), of the program below. def prob10(L): s...
Problem 10 Write down the running time function, T(n), of the program below. def prob10(L): s = 0 for x in L: for y in L: if x+y % 10 == 0: print(x, y, x+y) s = s + x*y return s ​ ANSWER: T(n) = ... ***Big-O, Omega, Theta complexity of functions, Running time equations of iterative functions & recursive functions,  Substitution method & Master theorem Please answer within these topics.***
a) Let T(n) be a running time function defined as T(n) = 3n^2 + 2n +...
a) Let T(n) be a running time function defined as T(n) = 3n^2 + 2n + 5, is this ϴ(n^2 )? Explain prove your answer using the definitions of big-o and omega notations. b) Solve the following recurrence relations using Master theorem. a. ?(?) = 3? ( ?/3 ) + ? b. ?(?) = 5?( ?/2 ) + 2?^2 please help them with both
For the following program fragment, (1) give an analysis of the running time T(n) as a...
For the following program fragment, (1) give an analysis of the running time T(n) as a function of n and (2) give a big-O bound on the asymptotic running time (tight bounds for full credit). Sum = 0; for (i=0; i< n; i++)    for(j=0; j < i*i; j++) if(j % i == 0) for (k=0; k<j; k++) Sum = Sum + 1;
Analyze the following codes by computing their running time, T(n). 1) int function ( int n)...
Analyze the following codes by computing their running time, T(n). 1) int function ( int n) { int sum; for (int i = 0; i < n; i++) ​ sum = sum + (i * n); return sum; } 2) int function(int n) { ​int sum; ​ ​for (int i = 0; i < n; i++) ​​if (n < 1000) ​​​sum++; ​​else ​​​sum += function(n); } 3) int function(n) { ​int s = 0; ​for (int i = 1; i...
Question 15: Use the Master theorem to find the asymptotic complexity of the running time function...
Question 15: Use the Master theorem to find the asymptotic complexity of the running time function T(n) of the program in problem 14. --- Problem 14 --- def prob14(L): if len(L) <= 1: return 0 output = 0 for x in L: for y in L: output += x*y for x in L: output += x left = L[ 0 : len(L)//2 ] right = L[ len(L)//2 : len(L) ] return output + prob15(left) + prob15(right) ***Big-O, Omega, Theta complexity...
Find T(t), N(t), aT, and aN at the given time t for the space curve r(t)....
Find T(t), N(t), aT, and aN at the given time t for the space curve r(t). [Hint: Find a(t), T(t), aT, and aN. Solve for N in the equation a(t)=aTT+aNN. (If an answer is undefined, enter UNDEFINED.) Function    Time r(t)=9ti-tj+(t^2)k t=-1 T(-1)= N(-1)= aT= aN=
Question 2: Calculate the time complexity function T(n) and express it in terms of big-Oh for...
Question 2: Calculate the time complexity function T(n) and express it in terms of big-Oh for the following code: Part a       (hint: make use of sum of geometric progression): for (int i=1; i <= n ; i = i*2) {           for ( j = 1 ; j <= i ; j ++)             {                       cout<<”*”;             } } Part b      (hint: make use of sum of square of a number sequence): for (int i=1; i <= n ; i...
QUESTION: write a program for the function : def collision(program1, start1, program2, start2): - takes program1...
QUESTION: write a program for the function : def collision(program1, start1, program2, start2): - takes program1 and start1 of a vehicle and program2 and start2 of another vehicle and checks whether the two vehicles will collide - if a collision occurs then a tuple must be returned containing (x,y) coordinates of the cell where the collision has occurred    - if the two vehicles collide in multiple cells the coordinates of the first cell must be returned where the collision has...
Develop a Java program for the question below: A running race among animals: In a race...
Develop a Java program for the question below: A running race among animals: In a race among animals different types of animals are differenciated wih their running styles. In each iteration of the race, each participating animal makes a move acording to its style of running. Total length of the racecourt is NTotal (store this variable properly in the test class). Determine the winner animal and completion time of the race using polymorphism. Each of these animal classes extends from...
Python , no strings, len(), or indexing Write the function setKthDigit(n, k, d) that takes three...
Python , no strings, len(), or indexing Write the function setKthDigit(n, k, d) that takes three # non-negative integers -- n, k, and d -- where d is a single digit # (between 0 and 9 inclusive), and returns the number n but with # the kth digit replaced with d. Counting starts at 0 and goes # right-to-left, so the 0th digit is the rightmost digit.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT