Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 22.4, Problem 22.4.6CP
Program Plan Intro
Refer the question 22.4.6 in the textbook which needs to compute the complexity of following term using brute force approach and Horner’s approach:
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In Python, write a recursive implementation of Fibonacci without memoization. Include a
timer to measure how long it takes.
The sequence is defined by this recurrence:
Fo = 0
F = 1
Fn = Fn-1+ Fn-2
The input should ask the user for the nth value in the sequence they want.
Improvement: have your solution print all the values it computes along the way to the nth
value in the sequence
Bonus Question
Improve the implementation above by using a memo dictionary (lecture notes slide 13)
Modeling the spread of a virus like COVID-19 using recursion.
Let
N = total population (assumed constant, disregarding deaths, births, immigration, and emigration).
S
n
= number who are susceptible to the disease at time n (n is in weeks).
I
n
= number who are infected (and contagious) at time n.
R
n
= number who are recovered (and not contagiuous) at time n.
The total population is divided between these three groups:
N = S
n
+ I
n
+ R
n
There are several hidden assumptions here that may or may not apply to COVID-19, such as a recovered
person is assumed to not be able to get the disease a second time, at least within the time window being
examined.
On week 0 (the start), you assume a certain small number of people have the infection (just to get things
going). Everyone else is initially susceptible, and no one is recovered.
There are two constants of interest:
Let period = time period that it takes for an infected person to recover (recover meaning they become
not infectious to…
suppose that n is not 2i for any integer i. How would we change the algorithm so that it handles the case when n is odd? I have two solutions: one that modifies the recursive algorithm directly, and one that combines the iterative algorithm and the recursive algorithm. You only need to do one of the two (as long as it works and does not increase the BigOh of the running time.)
Chapter 22 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 22.2 - Prob. 22.2.1CPCh. 22.2 - What is the order of each of the following...Ch. 22.3 - Count the number of iterations in the following...Ch. 22.3 - How many stars are displayed in the following code...Ch. 22.3 - Prob. 22.3.3CPCh. 22.3 - Prob. 22.3.4CPCh. 22.3 - Example 7 in Section 22.3 assumes n = 2k. Revise...Ch. 22.4 - Prob. 22.4.1CPCh. 22.4 - Prob. 22.4.2CPCh. 22.4 - Prob. 22.4.3CP
Ch. 22.4 - Prob. 22.4.4CPCh. 22.4 - Prob. 22.4.5CPCh. 22.4 - Prob. 22.4.6CPCh. 22.5 - Prob. 22.5.1CPCh. 22.5 - Why is the recursive Fibonacci algorithm...Ch. 22.6 - Prob. 22.6.1CPCh. 22.7 - Prob. 22.7.1CPCh. 22.7 - Prob. 22.7.2CPCh. 22.8 - Prob. 22.8.1CPCh. 22.8 - What is the difference between divide-and-conquer...Ch. 22.8 - Prob. 22.8.3CPCh. 22.9 - Prob. 22.9.1CPCh. 22.9 - Prob. 22.9.2CPCh. 22.10 - Prob. 22.10.1CPCh. 22.10 - Prob. 22.10.2CPCh. 22.10 - Prob. 22.10.3CPCh. 22 - Program to display maximum consecutive...Ch. 22 - (Maximum increasingly ordered subsequence) Write a...Ch. 22 - (Pattern matching) Write an 0(n) time program that...Ch. 22 - (Pattern matching) Write a program that prompts...Ch. 22 - (Same-number subsequence) Write an O(n) time...Ch. 22 - (Execution time for GCD) Write a program that...Ch. 22 - (Geometry: gift-wrapping algorithm for finding a...Ch. 22 - (Geometry: Grahams algorithm for finding a convex...Ch. 22 - Prob. 22.13PECh. 22 - (Execution time for prime numbers) Write a program...Ch. 22 - (Geometry: noncrossed polygon) Write a program...Ch. 22 - (Linear search animation) Write a program that...Ch. 22 - (Binary search animation) Write a program that...Ch. 22 - (Find the smallest number) Write a method that...Ch. 22 - (Game: Sudoku) Revise Programming Exercise 22.21...Ch. 22 - (Bin packing with smallest object first) The bin...Ch. 22 - Prob. 22.27PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Find f (1), f (2),f (3), and f (4) if ƒ (n) is defined recursively by f (0) =1 and for n = 0, 1, 2, . .. a) f (n+ 1) = f (n) + 2. b)f (n + 1) = 3f (n). c)f (n+ 1) = f (n)² +f (n) + 1. Give a recursive definition of the sequence {an}, n= 1, 2, 3, ... if а) а, — бп. b) a, 3 (п-1)?. c) a, = 2"+1arrow_forwardWrite a program in python that solves the following exercise, need an explanation of the solution: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.arrow_forwardQuestion 4: The function T(n) is recursively defined as follows: 1 if n = 1, 고 +. T(n -1) if n> 2. Prove that T(n) = 0(n log n).arrow_forward
- in Java Apply the Newton-Raphson's method xn+1 = xn – f '(xn) / f ''(xn) to develop a function double findMinMax(…) that returns a solution that is either a minimum value or a maximum value for z. The program finds a local minimum or a local maximum when the difference between the new solution and the previous one is smaller than 0.00001 within 10000 iterations. Otherwise, it shows Infinity as output. Let function z = x4+2y6 – xy – x + 2. Show the post-conditions for z. The preconditions for x and y are shown as below. Feel free to choose an arbitrary initial guess values x0 and y0 that meet the following precondition. |x| ≤ 6 and |y| ≤ 5arrow_forwardImplement a phi function that returns the count of coprime integers of a given positive integer n. Examples phi (1) 1 phi (3) 2 phi (8) → 4arrow_forwardDetermine the running time for each recursive functions 1. T(n) = T([n/2]) + 1 2. T(n) = T(n-1) + n 3. T(n) = 2T([n/2] + √n 4. T(n) = 16T([n/4]) + n2arrow_forward
- From Fundamentals of Discrete Math for Computer Science: A Problem-Solving Primer, 2nd edition Apply Algorithm 1.4.1 on P.38(picture attached) with f(x)=x^3+2^x, T = 100, A = 5, B = 4, δ = 0.1. Draw the corresponding walkthrough as shown in P.39(picture attached)arrow_forward2. Algorithm A has a running time described by the recurrence T(n) = 7T(n/2) + n². A competing algorithm B has a running time described by the recurrence T(n) = aT (n/4) + n². What is the largest integer value for a such that B is asymptotically faster than A? Explain your answer.arrow_forwardSolved in pythonarrow_forward
- There are two algorithms called alg1 and alg2 for a problem of size n. alg1 runs in n2 microseconds and alg2 runs in 100n log n microseconds. alg1 can be implemented using 4 hours of programmer time and needs 2 minutes of cpu time. on the other hand, alg2 requires 15 hours of programmer time and 6 minutes of cpu time. if programmers are paid 20 dollars per hour and cpu time costs 50 dollars per minute, how many times must a problem instance of size 500 be solved using alg2 in order to justify its development cost?arrow_forwardwrite a java algorithm to solvearrow_forwardYou have three algorithms to a problem and you do not know their efficiency, but fortunately, you find the recurrence formulas for each solution, which are shown as follows: A: T(n) = 5T (2) + (n) 9n B: T(n) 2T() + (n) 10 C: T(n) = T() + (n²) Please give the running time of each algorithm (In notation), and which of your algorithms is the fastest (You probably can do this without a calculator)?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education