0

For the following pseudocode, express what is returned as a function of n, and find the big-O notation for the worst-case running time.

I'm thinking O(n3) because it is three nested for loops, but I'm not really sure how to go about this more rigorously.

function pesky(n)
r <- 0
for i <- 1 to n do
    for j <- 1 to i do
        for k <- j to i+j do
            r <- r + 1
        end for
    end for
end for
return r
nbro
  • 15,395
  • 32
  • 113
  • 196
  • Advice: try first to understand what the function does: this may also help you to understand how it does it, and therefore help you in counting the total number of operations and iterations. – nbro Oct 01 '17 at 15:30
  • hm yes it is indeed a duplicate! – Yepyepyep Oct 01 '17 at 16:25

0 Answers0