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 given time complexity is:
m T(m-1) + ca > 1
cb = 0
expanding using substitution:
m T(m-1) + ca
m[(m-1) T(m-2) + ca]+ ca
m(m-1) T(m-2) + mca + ca
m(m-1) [(m-2) T(m-3) + ca] + mca + ca
m(m-1)(m-2) T(m-3) + m(m-1)ca + mca + ca
what is the time complexity?
form an expression for adding all the ca
Consider the problem of counting, in a given text, the number of substrings that start with an A and end with a B. For example, there are four such substrings in CABAAXBYA.a. Design a brute-force algorithm for this problem and determine its efficiency class.b. Design a more efficient algorithm for this problem with complexity O (n)
I'm trying to understand how both of these algorithms, separated by a) and b), have a time complexity of O(n), could you explain how this is?
a)int i = 0;while (i < n) { ... i++;}for(int j = 3; j < n * n; j += n) { ...}int k = 1;while (k < n) { ... k *= 2;}
b)for(int i = 1; i < n; i += 3) { for(int j = 3; j < 10; j++) { for(int k = 5; k < n; k += n) { ... } }}
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
- Develop a brute-force algorithm that finds the longest common sequential elements of two given lists with the Java programming language. For example, the following two lists are given: S1 = [B,C,D,A,A,C,D] S2 = [A,C,D,B,A,C] Common lists are: [B,C], [C,D,A,C], [D,A,C], [A,A,C], [A,C], [C,D], … Note that although both lists have a common [C,D,A,C] (sub)list, both list items are skipped and the left-to-right order is intact. Apply the brute force algorithm. Explain Time Complexity?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_forwardModeling 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_forward
- Consider a divide-and-conquer algorithm that calculates the sum of all elements in a set of n numbers by dividing the set into two sets of n/2 numbers each, finding the sum of each of the two subsets recursively, and then adding the result. What is the recurrence relation for the number of operations required for this algorithm? Answer is f(n) = 2 f(n/2) + 1. Please show why this is the case.arrow_forwardInformation is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply divide-and-conquer algorithm in the problem. Make sure all test cases return expected outputs. Hint: Apply bisection method/modules Output FormatOutput contains a line with two space-separated integers W_a and W_b.- W_a is the maximum matchups won by Hamiltonia- W_b is the maximum matchups won by Burrgadia. Sample Input 03 554402410 Sample Output 03 0 Sample Input 15 4833485183 Sample Output 12 2 Sample Input 27 81028121912601319851 Sample Output 27 0 The actual code """Solves a test case Parameters:a : int - number of leaders in Hamiltoniab : int - number of leaders in Burrgadias_i : array-like - rap proficiencies of Hamiltonia's leadersr_j : array-like - rap proficiencies of Burrgadia's leaders Returns:win_a : int - number of…arrow_forwardYou will analyze three algorithms to solve the maximum contiguous subsequence sum problem, and then evaluate the performance of instructor-supplied implementations of those three algorithms. You will compare your theoretical results to your actual results in a written report. What is the maximum contiguous subsequence sum problem? Given a sequence of integers A1, A2, ..., An (where the integers may be positive or negative), find a subsequence Aj, ... , Ak that has the maximum value of all possible subsequences. The maximum contiguous subsequence sum is defined to be zero if all of the integers in the sequence are negative. Consider the sequence shown below. A1: -2 A2: 11 A3: -4 A4: 13 A5: -5 A6: 2 The maximum contiguous subsequence sum is 20, representing the contiguous subsequence in positions 2, 3, and 4 (i.e. 11 + (-4) + 13 = 20). The sum of the values in all other contiguous subsequences is less than or equal to 20. Consider a second sequence, shown below. A1: 1…arrow_forward
- What is the asymptotic analysis of the algorithm for 2.1 f(n) = log x + n² + 14n + 15 is f(n) in O(n²), O(n³), 2(n²), Q(n), O(n² ), O(n), Q(n³), O(n), or ©(n³ ). 2.2 f(n) = 45x³ + 15x2 + 26x + 10 is f(n) in O(n?), O(n³), Q(n²), Q(n), O(n² ), 0(n), Q(n³), O(n), or 0(n³ )arrow_forwardWrite a python program based on the discussion we had on the last day of class, to train a network with two hidden layers each with 5 neurons. Finish the gradient computation we did in class, and implement a steepest decent search for a network which minimizes the cost function. Once you believe that your network is trained, compute the value of n(1, 1) and see what you get. Bonus: If you easily get this to work, then try to generalize to K neurons in each of the two hidden layers. Does the training work better with more neurons?arrow_forwardCorrect answer will be upvoted else downvoted. Computer science. Allow us to signify by d(n) the amount of all divisors of the number n, for example d(n)=∑k|nk. For instance, d(1)=1, d(4)=1+2+4=7, d(6)=1+2+3+6=12. For a given number c, track down the base n to such an extent that d(n)=c. Input The principal line contains one integer t (1≤t≤104). Then, at that point, t experiments follow. Each experiment is characterized by one integer c (1≤c≤107). Output For each experiment, output: "- 1" in case there is no such n that d(n)=c; n, in any case.arrow_forward
- Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply dynamic programming. Do not use recursion. Make sure ALL test cases return expected outputs. Output FormatOutput a single line containing the fastest time to get to square N from square 1. Sample Input 05 2 1 4 13 Sample Output 06 Explanation 0The optimal answer is to: RUN to square 2 (+2 seconds). Sonic now has 1 energy. DASH to square 3 (+1 second). Sonic now has 0 energy. RUN to square 4 (+2 seconds). Sonic now has 1 energy. DASH to square 5 (+1 second). Sonic now has 0 energy. Total time is 6 seconds. Sample Input 15 4 2 10 0 Sample Output 112 Explanation 1The optimal answer is to: RUN to square 2 (+4 seconds). Sonic now has 1 energy. RUN to square 3 (+4 seconds). Sonic now has 2 energy. DASH to square 4 (+2 seconds). Sonic now has 1 energy.…arrow_forwardWrite a Brute force algorithm to find all the common elements in two lists of integer numbers. (e.g., the output for the lists [1, 3, 4, 7] and [1, 2, 3, 4, 5, 6] should be 1, 3, 4). Show the time complexity of the algorithm if the lengths of the two given lists are m and n, respectively.arrow_forwardWhat is the worst case size of SL and SR (in terms of n) when you divide a list of unsorted items of size n into groups of (2*9)+1 while selecting a pivot? Input your answer as a decimal to three places. E.g. 3n/8 would be 0.375arrow_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