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
The speed of computers has increased greatly over the history of computing. The traveling salesman problem attempts to find a pathway for a salesman to visit all of the cities on his route using the shortest distance. The brute force method for solving this problem looks at all possible permutations of the cities. There are n! such permutations (where n! = n * (n-1) * (n-2) *…*1). Thus, 5! = 120. Current computers are running with clock speeds in the GigaHz range (10,000,000 times faster than the earliest computers) and they still are not able to solve the traveling salesmen problem using this brute force method for moderate values of n (like 50). If technology keeps moving ahead at the current rate, will this problem soon become feasible (yes or no)? Back up your answer with some sample numbers concerning factorials and speed of computers.
The following method of computing a is due to Archimedes:
1. Let A = 1 and N = 6
2. Repeat 10 times, say:
Replace N by 2
Replace A by [2 – V(4 – A?)]/2
Let L = NA/2
Let U = L/I- A² /2
Let P = (U + L)/2 (estimate of n)
Let E = (U - L)/2 (estimate of error)
Print N, P, E
3. Stop.
Write a program to implement the algorithm.
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)
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
- 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…arrow_forwardThe binomial coefficient C(N,k) can be defined recursively as follows: C(N,0) = 1, C(N,N) = 1, and for 0 < k < N, C(N,k) = C(N-1,k) + C(N - 1,k - 1). Write a function and give an analysis of the running time to compute the binomial coefficients as follows: A. The function is written using dynamic programming.arrow_forwardThe binomial coefficient C(N,k) can be defined recursively as follows: C(N,0) = 1, C(N,N) = 1, and for 0 < k < N, C(N,k) = C(N-1,k) + C(N - 1,k - 1). Write a function and give an analysis of the running time to compute the binomial coefficients as follows: A. The function is written recursively.arrow_forward
- 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_forwardEvaluation of Polynomial Function A polynomial of degree n is a function of the form f(x) = anx" + an-1x"-1 +...+ azx2 + a1x + ao where the as are real numbers (sometimes called the coefficients of the polynomial). Although this general formula might look quite complicated, particular examples are much simpler. For example, f(x) = 4x3 – 3x² + 2 %3D is a polynomial of degree 3, as 3 is the highest power of x in the formula. This is called a cubic polynomial, or just cubic.arrow_forwardFind f (2), f(3), f (4), and ƒ (5) if f is defined recursively by ƒ (0) = f(1) = 1 and for n = 1, 2, 3.... a) f(n+1) = f(n)-f(n-1). b) f(n + 1) = f(n) f(n-1) c) ƒ (n + 1) = f(n)² + f (n − 1)³ d) f(n + 1) = f(n)/ f(n-1)arrow_forward
- Suppose that f (n) = 0(g(n)) and f(n) = 0(h(n)), then it is ( always / sometimes / never ) the case that g(n) = 0(h(n)).arrow_forwardsuppose 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.)arrow_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_forward
- The Fibonacci function f is usually defined as follows. f (0) = 0; f(1) = 1; for every n e N>1, f (n) = f(n – 1) + f(n – 2). Here we need to give both the values f(0) and f(1) in the first part of the definition, and for each larger n, f(n) is defined using both f(n - 1) and f(n- 2). Use induction to show that for every neN, f(n) 1; checking the case n = 1 separately is comparable to performing a second basis step.)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_forwardApply algorithm 4.3.3 in P.158 with n=6 and A=(3,5,4,1,3,2). Draw the corresponding walkthrough as shown in P.158.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