Need this Find theta notation as a function of n for the nu

Need this:

Find theta - notation (as a function of n) for the number of times the statement \"x = x + 1\" is executed in the following pseudocode: for i = 1 to n for j = 1 to i for k = 1 to j x = x + 1

Solution

Theta(n) means that the algorithm is both big-O and big-Omega in the given function.

For example, if the function is (n), then there is some constant K, such that the function runtime is larger than n*K for sufficiently large n, and some other constant k such that the function is smaller than n*k for sufficiently large n.

In our scenario for the three for loops the running time would be theta(n^3).because every for loop runs for n times then only the statement x=x+1 gets executed.

For i=1 to n (executes n times)

For j=1 to i (executes n times)

For k=1 to j(executes n times)

Total running time =theta(n^ 3)

Need this: Find theta - notation (as a function of n) for the number of times the statement \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site