Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 4, Problem 4P
(a)
Program Plan Intro
To show that
(b)
Program Plan Intro
To show that
(c)
Program Plan Intro
To show that
(d)
Program Plan Intro
To show that
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
HW7_2 This problem uses an interpolating polynomial to
estimate the area under a curve. Fit the interpolating
polynomial to the following set of points. These points are
the actual values of f(x) = sin (e* – 2)
0.4
0.8
1.2
1.6
y -0.8415 |-0.4866 0.2236 0.9687 0.1874
a) Plot the function f(x) and the interpolating polynomial, using different colors. Use polyfit and
polyval. Also include the data points using discrete point plotting.
b) We wish to estimate the area under the curve, but this function is difficult to integrate. Hence, instead
1.6
of finding ° sin(e* – 2) dx (which is the same as finding the area under the curve sin (e* – 2) ),
we will compute the area under the interpolating polynomial over the domain 0
Ql: The Collatz conjecture function is defined for a positive integer m as
follows. (COO1)
g(m) = 3m+1 if m is odd
= m/2 if m is even
=1 if m=1
The repeated application of the Collatz conjecture function, as follows:
g(n), g(g(n)), g(g(g(n))), ...
e.g. If m=17, the sequence is
1. g(17) = 52
2. g(52) = 26
3. g(26) = 13
4. g(13) = 40
5. g(40) = 20
6. g(20) = 10
7. g(10) = 5
8. g(5) = 16
9. g(16) = 8
10. g(8) = 4
11. g(4) = 2
12. g(2) = 1
Thus if m=17, apply the function 12 times in order to reach m=1. Use
Recursive Function.
Quadratic Root Solver
For a general quadratic equation y = ax? + bx + c, the roots can be classified into
three categories depending upon the value of the discriminant which is given by
b2 - 4ac
First, if the discriminant is equal to 0, there is only one real root. Then, if the discriminant
is a positive value, there are two roots which are real and unequal. The roots can be
computed as follows:
-b+ Vb? – 4ac
2a
Further, if the discriminant is a negative value, then there are two imaginary roots. In
this case, the roots are given by
b
ь? - 4ас
2a
2a
Programming tasks:
A text file, coeff.txt has the following information:
coeff.txt
3
4
4
4
1
4
Each line represents the values of a, b and c, for a quadratic equation. Write a program
that read these coefficient values, calculate the roots of each quadratic equation, and display
the results. Your program should perform the following tasks:
• Check if the file is successfully opened before reading
• Use loop to read the file from main…
Chapter 4 Solutions
Introduction to Algorithms
Ch. 4.1 - Prob. 1ECh. 4.1 - Prob. 2ECh. 4.1 - Prob. 3ECh. 4.1 - Prob. 4ECh. 4.1 - Prob. 5ECh. 4.2 - Prob. 1ECh. 4.2 - Prob. 2ECh. 4.2 - Prob. 3ECh. 4.2 - Prob. 4ECh. 4.2 - Prob. 5E
Ch. 4.2 - Prob. 6ECh. 4.2 - Prob. 7ECh. 4.3 - Prob. 1ECh. 4.3 - Prob. 2ECh. 4.3 - Prob. 3ECh. 4.3 - Prob. 4ECh. 4.3 - Prob. 5ECh. 4.3 - Prob. 6ECh. 4.3 - Prob. 7ECh. 4.3 - Prob. 8ECh. 4.3 - Prob. 9ECh. 4.4 - Prob. 1ECh. 4.4 - Prob. 2ECh. 4.4 - Prob. 3ECh. 4.4 - Prob. 4ECh. 4.4 - Prob. 5ECh. 4.4 - Prob. 6ECh. 4.4 - Prob. 7ECh. 4.4 - Prob. 8ECh. 4.4 - Prob. 9ECh. 4.5 - Prob. 1ECh. 4.5 - Prob. 2ECh. 4.5 - Prob. 3ECh. 4.5 - Prob. 4ECh. 4.5 - Prob. 5ECh. 4.6 - Prob. 1ECh. 4.6 - Prob. 2ECh. 4.6 - Prob. 3ECh. 4 - Prob. 1PCh. 4 - Prob. 2PCh. 4 - Prob. 3PCh. 4 - Prob. 4PCh. 4 - Prob. 5PCh. 4 - Prob. 6P
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
- Correct answer will be upvoted else downvoted. Computer science. Positive integer x is called divisor of positive integer y, in case y is distinguishable by x without remaining portion. For instance, 1 is a divisor of 7 and 3 isn't divisor of 8. We gave you an integer d and requested that you track down the littlest positive integer a, to such an extent that a has no less than 4 divisors; contrast between any two divisors of an is essentially d. Input The primary line contains a solitary integer t (1≤t≤3000) — the number of experiments. The primary line of each experiment contains a solitary integer d (1≤d≤10000). Output For each experiment print one integer a — the response for this experiment.arrow_forwardComparison with analytic solution The analytic solution for free-fall with ²-dependent air drag is: Yanalyt (t) = yo + Vanalyt (t) 2m DpA In [] # Analytic solution In cosh 2mg DpA (√² ;)] Dp Ag 2m t Dp Ag 2m tanh Exercise 2: Write code for the analytic velocity solution In the code cell below, we already implemented the equation for y_analyt. Add the equation for the velocity, storing the result in v_analyt. The hyperbolic tangent function is available as np. tanh. For the time t, use the vector time that we populated in the loop above. Note: If your code generates any error message (in red), you need to fix this error before continuing. Get help from your instructor or classmates if needed. You will need to use some parentheses () for the trigonometric and square root functions, and to enforce the order of operations. However, use them only where necessary; an excessive number of parentheses makes it harder to debug your code. y_analyt = y0 + 2*m/(D*rho*A) * np.log(np.cosh…arrow_forwardPYTHON /JUPYTER NOTEBOOKS Program a backward solver (i.e. write your code) for an upper triangular system Ux=b. The algorithm is attached below for Numpy and Python with offset 1. Recall that NumPy and Python have offset 0 for their sequence data types.arrow_forward
- Python application creation The system call inv in the numpy.linalg library can be used to calculate the inverse of a matrix. A basic 2 by 2 matrix's inverse can be calculated using Python code. The identity matrix I is then generated by multiplying the inverse of A by itself for proof.arrow_forward8- Determine if each of the following recursive definition is a valid recursive definition of a function f from a set of non-negative integers. If f is well defined, find a formula for f(n) where n is non- negative and prove that your formula is valid. a. f(0) = 2,f(1) = 3, f(n) = f(n-1)-1 for n ≥ 2 b. f(0) = 1,f(1) = 2, f(n) = 2f (n-2) for n = 2arrow_forwardlet X = {0, 1}arrow_forward
- True or False 1. Matrices are often represented by single small letters a, b, c... etc.2. Two m x n matrices A and B are equal if aij=bij for each i & j. (i.e., the two matrices havesame size, and all the corresponding elements are equal).3. Matrices A & B are said to be conformable in the order AB if, and only if, the number ofrows in A is equal to the number of columns in B.4. Suppose Matrix A is having 4 rows and 3 columns, and Matrix B is having 3 rows and 2columns. The product size of AB is a 4 x 2 matrix.5. Suppose B is the matrix obtained from an n x n matrix A by multiplying the entries in arow/column by a non-zero constant and adding the result to the corresponding entries inanother row/column. Then, det(B) = det(A).arrow_forward1. A set of integers are relatively prime to each other if there is no integer greater than 1 that divides all the elements. Furthermore, in Number Theory, it is known that the Euler function,ϕ (n), expresses the number of positive integers less than n that are relatively prime with n. Choose the alternative that has the correct value of ϕ(n) for every n below. A) ϕ(5) = 4 B) ϕ(6) = 2 C) ϕ(10) = 3 D) ϕ(14) = 6 E) ϕ(17) = 16arrow_forwardWrite a program that does the following: 1- Ask the user to enter the number of variables on a Linear- System 2- Ask the user to enter matrix elements 3- Ask the user enter vector elements 4- Ask the user to enter initial approximation for the solution 5- Solve the linear-system using Jacobi iteration and show the results and number of iterations needed 6- Solve the linear-system using Gauss-Seidel iteration and show the results and number of iterations needed 7- Show which of the two methods is betterarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning