Question

In: Computer Science

You have been asked to create a program that builds a tower base on the number...

You have been asked to create a program that builds a tower base on the number of items given as input.

When the only 1 item is given you create no tower you just place the item on top of the stand.

When 2 items are given you build the base of the tower with one foot to the right and one foot to the left.

The feet will be in the ground and support the tower.

For every additional item you must keep the tower balanced by placing half on the right and half on the left each side

What is the height of the tower for the number 5? _________

What is the height of the tower for the number 10? ________

Write the a function to calculate the height. _______

If this was coded recursively what would be the base case? _________

If this was done recursively what would be the Time Complexity? _____

Solutions

Expert Solution

Answer :

What is the height of the tower for the number 5?

Height is 2. Make a base with 3 items and place two item on them. Like shown in figure.

What is the height of the tower for the number 10?

Height is 4.

Write the a function to calculate the height.

  1. start with size of base x = 1,
  2. subtract x from n
  3. now increase x by 1
  4. check if we can make new base or not i.e. x < n. If yes go to step 2
  5. return height

C++ function :

int height(int n, int x=1)
{
   if(n < x)
       return 0;
  
   return 1 + height(n-x, ++x);
}

call using height(n);

If this was coded recursively what would be the base case?

It should check the remaining item can make new base layer of size x or not.

If this was done recursively what would be the Time Complexity?

Time complexity : O(logn)

Hope you like it

Any Query? Comment Down!

I have written for you, Please up vote the answer as it encourage us to serve you Best !


Related Solutions

You have been asked to create a python program that will ask the user how many...
You have been asked to create a python program that will ask the user how many tickets the user would like to purchase for graduation. The user will then choose the number of tickets needed and the program will list the cost of the tickets, a service fee, tax, and the total of the purchase. Specifications: The program should only accept whole numbers when receiving input for the number of tickets needed. No calculations should be performed if input is...
You have been asked to create a brief education program to prepare outpatients for screening colonoscopy...
You have been asked to create a brief education program to prepare outpatients for screening colonoscopy for the gastroenterology department at the hospital where you work. The request was made because feedback from a significant number of patients who received the screening last year indicated that they wished they would have known what to expect in advance. Identify the theory or theoretical model that would be the best fit for use in developing an intervention or education program to address...
You have been asked to write program that allows the user to input a first name,...
You have been asked to write program that allows the user to input a first name, middle initial (without the period), and last name of a user and then display that person’s name with the first, middle initial followed by a period, and last name last. BEFORE creating the program, use structured programming principles to document how you are going to develop the program. Use Microsoft Word to complete this part of the assessment. Answer each of the following areas:...
2. You have been asked to `present on the foundational principles of conditioning program design to...
2. You have been asked to `present on the foundational principles of conditioning program design to a group of dieticians who have studied exercise science in theory, but now seek ideas on how to apply their knowledge in practice. Draft 6-8 key talking points to illustrate scientific exercise programming principles and expand on each of the talking points you identify to clarify their application.
You have been asked to study the effects of an employee-wide training program, in a company...
You have been asked to study the effects of an employee-wide training program, in a company of 500 employees, designed to reduce the amount of customer complaints. Describe how you would carry out the study, including the variable or variables you would collect, how you would measure those variables, and what would indicate success.  
(please do the all questions. Thanks) A Dice Game a) You have been asked to create...
(please do the all questions. Thanks) A Dice Game a) You have been asked to create a Die class which will be used to represent dice in computer games. The Die class should have the following fields: sides. The number of sides the die will have. value. The current value the die is displaying. In addition, the class should have a following methods. A Constructor which sets the number of sides and performs an initial roll of the die. A...
You have been asked by the Payroll Manager, Linda Laporte, to create a short job aid...
You have been asked by the Payroll Manager, Linda Laporte, to create a short job aid to assist the payroll practitioners with reconciling the Revenu Québec (RQ) account. Your organization is a monthly remitter. In your own words, outline suggested reconciliation methods including the forms, tools and reports that would be used in the process.
You have been asked to design a resistance training program for an experienced weight lifter who...
You have been asked to design a resistance training program for an experienced weight lifter who is training for maximal power. Briefly explain the importance of repetition velocity in power development
Imagine that you are asked to create a dissemination plan for a health promotion program. You...
Imagine that you are asked to create a dissemination plan for a health promotion program. You have just learned that most of the stakeholders that you planned to present to are leaving the country in two weeks and will be gone for the next six months, so you must present your findings to them before they leave. Originally, you had three months to prepare your dissemination plan. Do you think that the plan should be disseminated as it would be...
Phyton Question: You have been hired to create a program that computes that Monthly Net Pay...
Phyton Question: You have been hired to create a program that computes that Monthly Net Pay for a worker after acquiring from the user their Annual Gross Salary. The deductions that are to be considered are an Income Tax of 22.5%, a Social Security Tax of 6.2%, and a Medicare Tax of 1.45%. The program should end by displaying the Monthly Net Pay to the user. Design the algorithm for this program using your preferred method of representation (Pseudocode OR...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT