educative.io

Pls help me on challenge4: nested loop with multiplication, thx

hi, l got the answer is 4+2log3(n)+log3(n)+2log3(n)+log3(n)(n/2)+log3(n)(n/2)+log3(n)(n/2)2+1,which is different from the solution answer.
l see there are 3 places different.
First, while var< n: l get 2
log3(n) but answer is only log3(n), why? Is it because n not be counted?
Second, j in range(1,n,2): i get log3(n)
(n/2)+log3(n)(n/2) but answer is only log3(n), why?
Third, sum++:i get log3(n)
(n/2)2 but answer is log3(n)(n/2). why?

looking for helping me. thank u so much!

Hi @yan1,

Thank you for your question. So it seems that all of your values are twice what we have so ultimately, the time complexity comes out to be the same once the constants drop out. However, we’d like to know a bit more about how you calculated each of these. That would help us understand what’s causing the discrepancy. Looking forward to hearing from you, thanks!

– Team Educative