Bifalgorithm post
The average time to solve this problem is 10 minutes. Let's take a look. Question number 4. What is the runtime of the code? We have a loop here that starts at 1 and it goes up to i less than n and the value of i will double each time. So I hope you guys understand this problem better. Let's go through an example. Let's have n equals 20 and then we start at i equals 1 and if we multiply by 2 we're gonna get 2. Then we multiply this by 2 again so we get 4. 16 times 2 is 32. 32 is greater than 20 so we can ignore this case. So for n equals 20, we only get 5 possible values of i. However, if we count it by 1 each time, we're gonna have 20 values of i. And by doubling each time, we're essentially splitting our problem in half each time. And after dividing the problem, it's gonna look like this. And this algorithm is known as divide and conquer. And so the answer is all of log in.
The average time to solve this problem is 10 minutes. Let's take a look. Question number 4. What is the runtime of the code? We have a loop here that starts at…
Ideas in this flowchart
- Problem Analysis
- Problem Statement
- Question 4: Runtime of Code
- Loop Description
- Example with n=20
- Iteration Process
- Doubling i
- 5 Possible Values of i
- Comparison with Counting by 1
- Divide and Conquer
- Logarithmic Complexity