Question #62637

Give the most compact theta notation for the number of times the statement
x = x + 1 is executed in the following pseudo-code:
for i = 1 to i = 3n − 1{
for j = 1 to j = n{
x = x + 1
}
}
1

Expert's answer

2016-10-13T10:38:03-0400

Answer on Question #62637 – Math – Algorithms | Quantitative Methods

Question

Give the most compact theta notation for the number of times the statement x=x+1x = x + 1 is executed in the following pseudo-code:

for i=1i = 1 to i=3n1i = 3n - 1 {

for j=1j = 1 to j=nj = n {

x=x+1x = x + 1

}

}

Solution

The inner loop with index jj performs the statement x=x+1x = x + 1's n times.

The loop with index ii performs the inner loop (3n1)(3n - 1) times.

Thus, both loops perform the statement x=x+1x = x + 1's (3n1)(3n - 1)'s n times.

Here (3n1)n=3n2n(3n - 1)n = 3n^2 - n is a quadratic function, drop the factor 3 and the low-order term n-n.

So the most compact theta notation for the number of times when the statement

x=x+1x = x + 1's is executed will be Θ(n2)\Theta(n^2).

Answer: Θ(n2)\Theta(n^2).

www.AssignmentExpert.com


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS