Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 22.3, Problem 22.3.3CP
a)
Program Plan Intro
Given code:
public static void mA(int n)
{
for ( int i = 0 ; i < n ; i ++) {
System.out.println(Math. random());
}
}
b)
Program Plan Intro
Given code:
public static void mB (int n)
{
for ( int i = 0 ; i < n ; i ++ )
{
for ( int j = 0; j < i ; j ++)
System.out.print(Math. random());
}
}
c)
Program Plan Intro
Given code:
public static void mC(int[ ] m)
{
for (int i = 0; i < m.length; i++)
{
System .out.print(m [i]);
}
for (int i=m.length-1;i>=0;)
{
System.out.print(m[i]);
i--;
}
}
d)
Program Plan Intro
Given code:
public static void mD (int[ ] m)
{
for (int i= 0; i < m.length; i++)
{
for ( int j = 0 ; j < i ; j ++)
System.out. print( m[ i ] * m[ j ]);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Find the O(n log n) time.
Interpolate the value of the f(2,5) using Lagrange's interpolation formula with the following set of data.
f(2) =5;
f(3)=-1; f(4)=3;
Take the precision as three digits by applying rounding methods.
Write the answer below:
P(2,5) =
Suppose that you want to calculate 1434661 · 3785648743 − 100020304 · 54300201. You are told thatthe answer is a positive integer less than 90. Compute the answer mod 10 and mod 9, then combineto get the answer. Show all the necessary work to obtain your answers. Note: This technique hasoften been employed to do calculations with large integers because most of the computations use smallintegers, with only the Chinese Remainder Theorem step requiring large integers. For example, if theanswer is known to be less than 1036, the calculations can be done mod p for each prime less than100. Since the product of the primes less than 100 is approximately 2.3 × 1036, the Chinese RemainderTheorem gives the answer exactly
Chapter 22 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
Similar questions
- Analyze Running Time. For each pseudo-code below, give the asymptotic running time in Θ notation. (You may assume that standard arithmetic operations take Θ(1) time.) You may assume that n is a power of two if it simplifies your analysis. Please explain in detailarrow_forwardIn Big-Θ notation, analyze the running time of the following piece of code/pseudo-code. Describe the running time as a function of the input size (here, n). You should always explain your work when solving mathematics problems.arrow_forwardtrace the following code and show your stepsarrow_forward
- Could you please help me find the time complexity for the following codes? Thank you.arrow_forwardThe summation of x is found by the statement y=prod(x) True O False To increase the accuracy of numerical integration, the step size of y values is .decreased True False Oarrow_forwardPlease answer the above calculate the time complexity show workingarrow_forward
- Using n as the input size, what is the running time of the following algorithm?arrow_forwardSolve the following recurrences using iteration methods and Master's Theorem (if possible) a. T(n) = 2T (n/3) +3 b. T(n) = 3T (n/6) + narrow_forwardWhich one of the following method requires less number of calculations per iteration.O Euler's MethodO Decoupled MethodO Gauss-Seidal MethodO Newton-Raphson Methodarrow_forward
- USING PYTHON NOT MATLAB We can use the sum of the first n terms of the Taylor series of e x with a = 0 to estimate the value of the exponential function. Using a logarithmic y axis, plot the fractional error in the estimated e x (compared to numpy.exp(x)) as a function of n (n ranging between 1 and 80) for (a) x = 15 and (b) x = −15. [You can plot the two cases either as different curves on the same plot or in different plots, whichever is clearer.] Discuss the contributions of truncation and roundoff to the fractional error for the different values of x and n. Also discuss how you could reduce truncation and roundoff errors in order to estimate e x more accurately using the Taylor series.arrow_forwardOverview One of the oldest methods for computing the square root e of a number is the Babylonian Method e. The Babylonian Method uses an iterative algorithm to make successively more accurate estimates of a number's square root. The algorithm stops iterating when the estimate shows no further sign of improvement, or when the estimate is within some acceptable margin of error. The acceptable margin of error is often called an epsilon. Assuming that you need to solve for the square root of x, the algorithm works as follows. 1. Choose an epsilon value that determines how close your solution should be to the actual square root value before you decide it is "good enough." Because this assignment asks you to solve for the square root to three decimal places, we can safely set the epsilon value to 0.0001 (four decimal places). This guarantees that our solution will be accurate to the precision we need to display to the screen. 2. Choose an initial estimate e for the square root of x. An easy…arrow_forwardAnalyze the following algorithm. Find their running time and asymptomatic notation.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