0
$\begingroup$

I would like help understanding this slide from my class, especially the inner loop part. I do not understand how he is getting at n - (n - 1 - 1) = 2

I do understand that when j = n - 1 we get n - (n - 1) but I don't get why we have an extra -1 there.

I'd appreciate if anyone could walk through their thought process for this, thank you!

enter image description here

$\endgroup$
1
  • $\begingroup$ Beware typos in the slide. For starters, there is one in 2.…for i = (j+1)…. Suggest using a font where the glyphs for $I, l$ and $1$ can be told from each other. $\endgroup$ Commented Sep 6, 2024 at 4:31

1 Answer 1

0
$\begingroup$

The n comparisons from 1. can only be comparing the control variable to the limit.

The $t_i$s are really $n - j + 1$ (+1 for the comparison of the control variable to the limit):
$n - (n-1) + 1$ for $j=n-1$.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.