I'd like to ask you a question about calculating the time complexity

Asked 2 years ago, Updated 2 years ago, 66 views

Is it n/2 or n/2 + 1 in this case?

2/2

I am still confused about the exam tomorrow...

c data-structure time-complexity

2022-09-22 14:54

1 Answers

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..


2022-09-22 14:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.