1
$\begingroup$

So I'm studying for my data structures midterm that's this monday, and my professor gave out a sample midterm with the answers, but I'm having a hard time understanding one of the questions.

Here's a screen cap:

enter image description here

Could someone give me a walk through of the math that's happening in each step? And possibly a conceptual explanation in computer science terms?

$\endgroup$
1
$\begingroup$

You see no matter what values i,j take, k goes from 1 to n. Thus cont will run n times runs of the first two loops. Consider i,j, fix i, j goes from 1 to i. Thus the total time complexity $$T(n)=n\cdot\left((1)+(1+2)+...+(1+2+...+n)\right)$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.