I am trying to solve the following problem. Could someone let me know if my logic is right? The answer should be expressed in Theta notation.
x = 0
for i = 1 to n do
for j = 1 to i do
for k = j to n do
x = x + 1
The second loop is run c*(1+2+3+4+...+n) = n(n+1)/2, so it the running time is Theta(n^2)
If the third loop runs at (n-j+1). How do I combine this with the second loop to find a total running time? Is it still Theta(n^2)?
x = 0
for i = 1 to n do
for j = 1 to i do
for k = j to n do
x = x + 1
The second loop is run c*(1+2+3+4+...+n) = n(n+1)/2, so it the running time is Theta(n^2)
If the third loop runs at (n-j+1). How do I combine this with the second loop to find a total running time? Is it still Theta(n^2)?