Is it n/2 or n/2 + 1 in this case?
2/2I am still confused about the exam tomorrow...
c data-structure time-complexity
for(i = 1; i < n ; i *= 2) printf("Hello"); In this case, i increases like an exponential function of 2. At this time, the time complexity is log with 2 down I think so. Namely log2(n).
for(i = 0; i < n ; i++) for(j = 1; j < n; j *=2) printf("hello") In the same case, I think it's n from the front and log to the back and down 2 as well.
Porridge n *log2(n).
To represent the time complexity, you can use an expression to represent the number of times you calculate..
© 2024 OneMinuteCode. All rights reserved.