Count operation Lucky twos
Lucky Twos determines and displays the number of digits that are 2s in a whole number. For example, the number of 2s in 3487 is 0, while the number of 2s in 272521 is 3. Note: whole numbers are non-negative integers starting at zero 0, 1, 2, 3, 4.
Assume that the fractional part is discarded in the division:
10 / 4 = 2
8 / 5 = 1
20 / 3 = 6
Read number
set count to 0
while number > 0
If the number module 10 is Then add
1 to count
End If
Compute number as number / 10
End while
Display count.
Let n be the number of digits of the whole number. What is the number of operations that are executed in the code in terms of n?

Respuesta :

Answer:

Following are the solution to this question:

Explanation:

Its complexity of both the pseudo-code described is indeed proportional to the number of digits. So, how often number there are in this specific number is the query. Whenever a number is considered, the d digit would be between [tex]10^{(d-1)}.[/tex] inclusive exclusive [tex]10^d[/tex] That would be as, let d become the number of digits at N, and the inequalities, They can tell

[tex]10^{(d-1)} \leq N < 10^d[/tex]

We get, we take a logarithm,

[tex]d-1 \leq \log(N) < d[/tex]

The increase of 1 to the left inequality, [tex]d \leq \log(N)+1[/tex], and Combining the previous outcome, we got, [tex]\log(N) < d \leq \log(N) + 1[/tex]. That's would be to say, that number of number d by [tex]O(\log(N))[/tex] is higher and lower. Consequently, the number of transactions in the code is [tex]O(\log(N))[/tex]

We have that the number of operations that are executed in the code in terms of n  is mathematically given as

The quantity of operations done in the code is O(log(N))

Operation

Generally the equation for the   is mathematically given as

If we think about a number,

with d digits is between 10^(d-1) inclusive and 10^d exclusive.

Let d be the wide variety of digits in N

10^(d-1) <= N < 10^d

d-1 <= log(N) < d

d <= log(N) + 1,

The Inequality

log(N) < d <= log(N) + 1.

Therefore

The quantity of operations done in the code is O(log(N))

For more information on Inequality visit

https://brainly.com/question/19491153