Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 5, Problem 5.19HW
Program Plan Intro
Given C Code:
void psum1a(float a[], float p[], long n)
{
long i;
float last_val, val;
last_val = p[0] = a[0];
for(i=1; i<n; i++)
{
val = last_val + a[i];
p[i] = val;
last_val = val;
}
}
Cycles per element (CPE):
- The CPE denotes performance of
program that helps in improving code. - It helps to understand detailed level loop performance for an iterative program.
- It is appropriate for programs that use a repetitive computation.
- The processor’s activity sequencing is controlled by a clock that provides regular signal of some frequency.
Loop unrolling:
- It denotes a program transformation that would reduce count of iterations for a loop.
- It increases count of elements computed in each iteration.
- It reduces number of operations that is not dependent to program directly.
- It reduces count of operations in critical paths of overall computations.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Note: Please Answer in C++ programming language.
Kulyash is given an integer N. His task is to break Ninto some number of (integer)
powers of 2. To achieve this, he can perform the following operation several times
(possibly, zero):
Choose an integer X which he already has, and break X into 2 integer parts
(Y and Z) such that X = Y + Z.
Find the minimum number of operations required by Kulyash to accomplish his task.
Input
1
3
Output
1
Using any digital flowcharting tool ( Lucidchart, Vizio), write 4 UML functions. Each one should take in a pair of numbers and then print out all integer values between (and including) those two numbers. You may assume the lower number comes first.
Use these 4 types of loop for each of the four functions: while, do-while, automatic counter, and recursion. Clearly identify each one.
2. There is a more efficient algorithm (in terms of the number of multiplications and additions
used) for evaluating polynomials than the conventional algorithm described in the previous
exercise. It is called Horner's method. This pseudocode shows how to use this method to find
the value of anx" + an-1xn ++ a₁x + ao = 0 at x = c.
procedure Horner(c, ao, a₁, a2,..., an: real numbers)
y := an
for i:=1 to n
y := y*c+an-i
return y(y = anc" +an-1c"1+...+ a₁c + ao}
2.a Evaluate 3x² + x + 1 at x = 2 by working through each step of the algorithm showing
the values assigned at each assignment step.
2.b Exactly how many multiplications and additions are used by this algorithm to evaluate a
polynomial of degree n at x = c? (Do not count additions used to increment the loop variable.)
Chapter 5 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Knowledge Booster
Similar questions
- In 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_forwardNeed the solution of the code step-by-step please!arrow_forwardConsider the infix expression exp = ( ( 8 / 2 ) + 3 ) * 1 to solve the questions given below: a: Trace the process of converting the infix expression into It's postfix form. b: Evaluate the postfix expression you obtained in part a. *************************************************************************************** Note: Solve the question in your notebook. Draw two tables as shown below. Scan or take a picture, upload the file. a: Next token Action Content of stack Postfix expression b: Next token Action Content of stackarrow_forward
- Code in Python. Write a Python program to display the graphs of the function f(x) = ln(1+x) and its Taylor series expansions with 2, 4, and 6 terms around the point x=0. Find out how many series terms need to be retained to calculate ln(0, 8) with absolute error less than 0.0001.arrow_forwardImplement the modular exponentiation (a.k.a. fast exponentiation) function mod_exp (b, n, m) to compute bn (mod m) more efficiently. (Hint: to read n bit-by-bit, use / and % operations repeatedly) a) Test your function for b = 3, n = 231 – 2, m = 231 – 1. b) Report the result and the time (in seconds) it takes to find the result. Q3. [30 pts] Modify your is_prime function to use the mod_exp (b, n, m) instead of the standard power operation (b**n % m). Rename it as is_prime2. Modify the mersenne (p) function to use is_prime2, and call it mersenne2. a) Use the modified function mersenne2 to print all the Mersenne primes Mp for p between 2 and 31 if possible, (with k = 3 in the is_prime function). Compare the results with the ones found in Q1. b) Gradually increase the range of p to find more Mersenne primes (say up to p = 101 if possible). What is the largest Mersenne prime you can achieve here? c) Extend the work in part (b) and find the maximum Mersenne prime you can get from this…arrow_forwardWrite an Arduino program for the following machine problems. The program sequence should run continuously. Set the delay to 1 second. (USE TINKEDCAD) Challenge Problem.Create a program that displays "AbC" one at a time. For every keypress of PB1 it should cycle from A->b->C and go back to A. For PB2, it is the opposite of PB1, from C->b ->A. PB1 and PB2 can be pressed anytime. For example, If the current display is “A” pressing PB2 would display “C” then pressing PB1 will display it back to “A” and so forth. PB3 is used to blank the display and reset the operation. Sample simulation is given belowarrow_forward
- Below C-code has a for loop which will repeat 1000 times of the operation. This code will be running on very simple machine. Change the code to reduce the number of branch instructions. You can have up to 5 lines (statements) within the for loop. What is the number of branch operations before and after? for (i=0; i<1000; i++){ y[i] = w * x[i] + b[i]; }arrow_forwardCould you help me write a python program for this: Apply the composite Gaussian Quadrature to approximate the integral (shown below) using N=10 subintervals. Calculate the absolute error using the exact integral. Repeat your calculation forN=10,20,30,40,50. Observe the error as N gets largerarrow_forwardImplement the modular exponentiation (a.k.a. fast exponentiation)function mod_exp (b, n, m) to compute bn (mod m) more efficiently. (Hint: toread n bit-by-bit, use / and % operations repeatedly)a) Test your function for b = 3, n = 231 – 2, m = 231 – 1.b) Report the result and the time (in seconds) it takes to find the result. in pahtonarrow_forward
- Write computer program to solve a set of equation by using Gauss-Seidel Iteration.arrow_forwardHere is my question that my professor gave to me as a homework from my algorithm's class.arrow_forwardPlease use pythoncode 6. Evaluate as accurately as possibleIntegral 0 to 1 2x+1/square roots of x(1-x) dx hint: substitute x=(1+t)/2.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