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?

Answers

Answer 1

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]

Answer 2

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


Related Questions

what technical was the microscope invented in?

Answers

Answer:

Two Dutch spectacle-makers and father-and-son team, Hans and Zacharias Janssen, create the first microscope in 1590.

Explanation:

A microscope is an instrument that makes an enlarged image of a small object, thus revealing details too small to be seen by the unaided eye. The most familiar kind of microscope is the optical microscope, which uses visible light focused through lenses. Eeuwenhoek observed animal and plant tissue, human sperm and blood cells, minerals, fossils, and many other things that had never been seen before on a microscopic scale. He presented his findings to the Royal Society in London, where Robert Hooke was also making remarkable discoveries with a microscope.

Classify the characteristics as abstract classes or interfaces.

A. Uses the implements keyboard
B. Cannot have subclasses
C. Does not allow static and final variables
D. Can have subclasses
E. Uses the extends keyboard
F. Allows static and final variables

Answers

E for eeeedeerreeeee

CH4 has how many of each type of atom?

Answers

Its easy that moderators that see this answer can think that my answer isn't without explanation.

• Type of atom C (Carbon)

C = 1

• Type of atom H (Hydrogen)

H = 4

You dont understand? JUST SEE THE FORMULA C MEANS ONLY HAVE 1 CARBON ATOM AND H4 MEANS 4 ATOM OF HYDROGEN

oK. have a nice day hope you understands

Why do we use return statements? Choose all that apply

A.
Javascript requires functions to have return values.

B.
To return multiple data types simultaneously

C.
To allow a function to give different values depending on input.

D.
So that we no longer have to use console.log();

E.
To save the result of a function in a variable in other functions

Answers

Answer:

A.

Javascript requires functions to have return values.

What infection type can send information on how you use your computer to a third party without you realizing it

Answers

Answer:

Spyware collects your personal information and passes it on to interested third parties without your knowledge or consent. they also install trojan horses

Explanation:

Need help plz with the code

Answers

Answer:

its blocked

Explanation:

Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
As long as x is greater than 0
Output x % 2 (remainder is either 0 or 1)
x = x // 2
Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.
Ex: If the input is:
6
the output is:
110
Your program must define and call the following two functions. The function integer_to_reverse_binary() should return a string of 1's and 0's representing the integer in binary (in reverse). The function reverse_string() should return a string representing the input string in reverse.
def integer_to_reverse_binary(integer_value)
def reverse_string(input_string)
Note: This is a lab from a previous chapter that now requires the use of a function.

Answers

Answer:

#include <iostream>//header file

#include <string>//header file

using namespace std;

string integer_to_reverse_binary(int integer_value)//defining a method integer_to_reverse_binary  

{

   string ret = "";//defining string variable

   while (integer_value > 0) //using while loop to check integer_value value is greater than 0

   {

       ret += '0' + (integer_value % 2);//adding zeros in remainder value

       integer_value /= 2;//holding quotient value

   }

   return ret;//return string value

}

string reverse_string(string input_string)//defining a method reverse_string that holds a parameter user_String  

{

   string result;//defining a string variable  

   for (int i = 0; i < input_string.length(); ++i)//use for loop to calculate value  

   {

       result += input_string[input_string.length()-i-1];//add value in result variable

   }

   return result;//result result variable value

}

int main()//defining main method  

{

   int num;//defining integer variable

   string str;//defining string variable

   cin >> num;//input num value

   str = integer_to_reverse_binary(num);//use str variable to call the integer_to_reverse_binary method

   cout << reverse_string(str) << endl;//printing the reverse_string method value

   return 0;

}

Output:

6

110

Explanation:

In this code two string method "integer_to_reverse_binary and reverse_string" is defined that holds one parameter "integer_value and input_string".

In the first method a string variable is defined, that use the while loop to check integer value is greater than 0 and add zeros in the value and return its value as a string.

In the second it reverse the string value and store into the result variable, and in the main method the "num and str" variable is defined, and in the num it takes integer value and pass into the above method and print its return value.    

What is the influence of new technology on society?
Ο Α. .
New technology hardly has any impact on society.
OB.
New technology is only beneficial to society and cannot be detrimental.
OC.
New technology is detrimental, as it makes the existing technology obsolete.
OD. New technology normally utilizes a lot of resources and can adversely affect the economy.
O E.
New technology is beneficial but can also be usedly a detrimental way.

Answers

Answer:

E. New technology is beneficial but can also be used in a detrimental way.

Explanation:

New technology such as cryptocurrency (powered by blockchain technology) can be regarded as a welcome development that has benefited the society in so many good ways. However, cryptocurrency as a new technology also has disadvantages it presents to the society. One of such negative influence cryptocurrency has is that it can be used for illicit activities such as money laundering, funding terrorism and so on.

So, in summary, we can conclude that:

"New technology is beneficial but can also be used in a detrimental way."

______ are special characters that allow you to
search for multiple words at the same time.
-Find expressions
-Defined expressions
-Regular expressions
-Search expressions

Answers

Answer:

Defined Expression

Explanation:

This will be your answer

How does the pay for many Science, Technology, Engineering, and Mathematics workers compare to the overall median for all careers? It is far lower than the overall median. It is far higher than the overall median. It is slightly higher than the overall median. It is about the same as the overall median.

Answers

Answer:

B

Explanation:

It just is

Answer:

B is correct

Explanation:

Other Questions
Which of the following was a result of the Kirk-Holden War in North Carolina?A. Colonel George Kirk's militia remained in control of North Carolina for the next 10 years.B. Colonel George Kirk was imprisoned and spent the rest of his life behind bars.C. Governor William Holden became the first governor to be impeached & removed from office.D. Wyatt Outlaw & John Stephens were elected to the state assembly & served the state for many years. Data on U.S. work-related fatalities by cause follow (The World Almanac, 2012). Cause of Fatality Number of Fatalities Transportation incidents 1795 Assaults and violent acts 837 Contact with objects and equipment 741 Falls 645 Exposure to harmful substances or environments 404 Fires and explosions 113 Assume that a fatality will be randomly chosen from this population. Round your answers to four decimal places. a. What is the probability the fatality resulted from a fall From the top of the stiffer mantle to the center of earth, the rock material is inferred to be (1) solid all way to the center of the inner core(2) solid, then liquid to the center of the inner core (3)solid, then liquid, then solid again to the center of the inner core (4) solid, then liquid, then gaseous to the center of the inner core three times Jeffs age is Kellys age Kelly is 48 years old what is Jeffs age what is 1x + 2x = 4x What kind of growth model (pattern) is shown in the table?X1234.55251256253,125square rootlinearexpggentialquadratic What is the value of log^381?A.2B.3C.4D.5 Pls help Ill mark brainliest 11. Todas las pelculas de Avengers en el cine son un ejemplo de: *Gnero lricoGnero dramticoGnero narrativo I need this quickly they both need expressions I think so (will mark brainlist if right) 1.1.2 Read: AP3X -Interviews about the Great Depression WILL MARK BRAINLIEST HUGE POINTS 1. Why did Lillian's family have to pawn the ivory dresser set? 2. What was Lillian's most treasured memory of her trip from Ohio to Virginia? 3. Why did James's father withdraw and bury his money? 4. Why do you think James did something similar so many years later? 5. What does it mean that the grocery store sold on credit? 6. Why do you think this story stood out to them? 7. Why did the man come up to the house? 8. Why do you think the father kept the watch all those years? 1. What is one theme or trend you see in these stories? 2. What can we learn about the Great Depression based on these stories? The equation for the area of a circle is given.A=r2If the radius (r) of the circle is 3, what is the area in terms of ? 1 point2. Due to its intricate network, minerals with sheet of tetrahedron do noteasily separate. *TrueFalse who do you think is most to blame for what happens to Gatsby in chapter 8 What type of force causes your car to move? Plz help!!!!!!!!!!!!!!!!! HURRY PLEASE... 75 POINTS Which one of the following statements is true concerning the magnitude of the electric field at a point in space? It is a measure of the electric force on any charged object. It is a measure of the ratio of the charge on an object to its mass. It is a measure of the electric force per unit mass on a test charge. It is a measure of the electric force per unit charge on a test charge. It is a measure of the total charge on the object. What human actions contributed to the nutrient pollution of Lake Okeechobee?PLZ HELP MEEEEEEEEEEEEEEEE I BEG YOU All hurricanes must have an energy source to form and grow. From where does this energy come?A. High air pressuresB. Warm ocean watersC. The Earth's rotation on its axisD. Warm air rises and pulls cooler air is pulled into it