
Concept explainers
Write pseudo code of the
“A firm wants to determine the highest floor of its n-story headquarters from which a gadget can fall without breaking. The firm has two identical gadgets to experiment with. If one of them gets broken, it cannot be repaired, and the experiment will have to be completed with the remaining gadget. Design an algorithm in the best efficiency class you can to solve this problem.” A prototype of the algorithm is given as:
int checkHeight(Building[1..n], W1, W2)
//Building with 1 to n floors and two weights w1, w2, and it will return the highest
//floor number from which the weight can fall safely. Whenever, you throw a weight,
//it will either break or do not break with a function ThrowWeight(FloorNo, W)
//It will return 1 if the weight does not break and 0 if it breaks.

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- In a fractional knapsack problem The first line of the input takes n, the number of items. In the next n lines, for each item (from 1 to n),you take the weight and the corresponding benefit. In the last line you take the knapsack capacity Wfrom the user.Output:In the output, you print out the items (in the increasing order) that has been selected, and for each itemhow much amount has been taken into consideration and what is the profit made from each item. Thelast line output the maximum profit that can be made.Sample Input54 128 322 406 301 5010Sample Output:Item 2 Amount 1 Profit 4Item 3 Amount 2 Profit 40Item 4 Amount 6 Profit 30Item 5 Amount 1 Profit 50Total Profit: 124arrow_forwardHi, how do we go about solving this problem in Java programming language? Input The input begins with an integer 1 ≤ ? ≤ 10000, the number of frosh. For each frosh, a line follows containing the course numbers of five distinct courses selected by the frosh. Each course number is an integer between 100 and 499. Output The popularity of a combination is the number of frosh selecting exactly the same combination of courses. A combination of courses is considered most popular if no other combination has higher popularity. Output a single line giving the total number of students taking some combination of courses that is most popular.arrow_forwardInterest on a credit card’s unpaid balance is calculated using the average daily balance. Suppose that netBalance is the balance shown in the bill, payment is the payment made, d1 is the number of days in the billing cycle, and d2 is the number of days payment is made before billing cycle. Then, the average daily balance is: averageDailyBalance =netBalance x d1-payment x d2d1 If the interest rate per month is, say, 0.0152, then the interest on the unpaid balance is: Interest= averageDailyBalance * 0.0152 Write a program using c++ compiler that accepts as inputnetBalance, payment, d1,d2, and interest rate per month. The program outputs the interest. Format your output to two decimal places.arrow_forward
- Python code plzz Don't copy i will rate..arrow_forwardWhen the robot makes a turn, it would be useful to have an operation to perform on d to represent this turn. This is because after making a turn, the new value of d will depend on the old value of d. Complete the table for the new values of d if the robot is turning left or right.Then determine an expression in terms of d that will give the new position if the robot turns left and another expression if the robot turns right. Type these expressions in the last row of the table. Attached is the table I completed. All rows are correct except the last one. I'm not sure what my error is.arrow_forwardThe square root of any number N>0 can be opproximated by repeated calculation using the formula N = squared_value NG = 0.5 (FG + N/FG) where NG stands for next guess and FG stands for first guess. The value of NG and FG are compared. If the two values are comparably close, then NG is the final answer. If the two values are off, NG becomes FG and the formula is used again to compute FG. After so many iterations, NG and FG will merge. a. Write a function that calculates the square root of a number using this method. The initial guess wilI be the starting value of FG (FG = 1). The function will compute a value for NG using the formula given and returns that value. (Change the name of the functions to something more meaningful) double fun_1 (double FG, double N); b. Write a function that prompts the user for any number N > 0, and returns that value back. The prototype is like follows: double fun_2 ( void ); Now inside the main function, check the difference between NG and FG to see whether…arrow_forward
- Q1 The periodic function sin(2x) has multiple roots between x values of -5π and 5π. If xL = -15 and xU = 15, which of the following statements is true using a bracketed method? Select one: a. All roots will be returned b. The middle root will be returned c. The chosen bracket is invalid for bracketed methods d. A single root will be returned e. The algorithm will be stuck in an infinite loop Q2 Consider x and y to represent data points (xi,yi), where i = 1, 2, 3, … n. What is the length of pafter running the following command? p = polyval(x,y) Select one: a. n b. n - 1 c. n + 1 d. Empty variable e. 1 Q3 Consider a system of linear equations in the form of AX = B, where X is the unknown vector. Which of the following can be used to solve for X? Select one: a. X = A\B b. X = B./A c. X = inv(B)*A d. X = inv(A)./B e. X = B\Aarrow_forwardcan you solve this please ?arrow_forwardplease code in python A classic example of this process is known as the "Drunkard’s Walk": a drunken student leaves a pub in Dinkytown and attempts to walk back home. The individual is so inebriated however, that when they arrive at each street intersection a random direction is chosen (including a u-turn!). The question arises: "what are the chances that the student will leave Dinkytown before morning?" Write a Python program using Turtle graphics that will visualize the Drunkard's Walk. Your program needs to do the following: Starting in the middle of the turtle window, obtain a random integer in the range [1,4] (use randint) and change the turtle heading to 0, 90, 180 or 270 based on the value of the integer: 1, 2, 3 or 4, respectively. You can use turtle.setheading(angle) to do this. Move the turtle one block (we’ll say forward 30 in turtle graphics represents one city block), in the new heading. Repeat this process 200 times. You may want to use turtle.speed(0) and…arrow_forward
- Please assist with problem.arrow_forward1. Both mergesort and quicksort uses divide and conquer paradigm to sort unsorted list. (a) Imagine you want to write the quicksort algorithm to sort an array into non-increasing order. Write down the partition algorithm that is used in the divide phase in the quicksort algorithm. Show that the time complexity of this algorithm is 0(n). (b) Identify the worst case situation in the naive quicksort algorithm and show that in the worst case situation its time complexity is O(n2)arrow_forwardCan the above algorithm be ran through a test example?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





