Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
3rd Edition
ISBN: 9780134123837
Author: Randal E. Bryant, David R. O'Hallaron
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 5.11, Problem 5.9PP
Program Plan Intro
Given C code:
void merge(long src1[], long src2[], long dest[], long n)
{
long i1 = 0;
long i2 = 0;
long id = 0;
while(i1<n && i2<n)
{
if(src1[i1]<src2[i2])
dest[id++] = src1[i1++];
else
dest[id++] = src2[i2++];
}
while(i1<n)
dest[id++] = src1[i1++];
while(i2<n)
dest[id++] = src2[i2++];
}
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.
Memory aliasing:
- It denotes a case where two pointers might designate to memory location that is same.
- The compiler should assume that unlike pointers might be aliased for safe optimizations.
- The program aspects that could limit chances for a compiler in generating optimized code denote optimization blockers.
- If a compiler is unable to determine whether two pointers might be aliased, it should adopt that either case would be possible.
- The possible optimization set is been limited in this case.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3. The diagram below shows the main land routes for vehicular traffic between points A and G in a city. The figures in the arcs represent the cost of traveling between each pair of nodes.
a) Manually apply Dijkstra's algorithm to find the cheapest route between A and G (visited nodes and total distance).
b) Formulate a linear programming problem in extended form, to determine the shortest route to travel from A to G. Do not use subscripts, name 14 variables, for example XFE would be the variable that indicates that the arc from F to E is used.
c) If there is a fixed cost for visiting each node, modify the formulation of the problem to include said fixed cost in the objective function, and the variables and restrictions that are required.
NODE
A
B
C
D
E
F
G
FIXED COST
25
18
32
20
28
18
34
R-13.17 - There are eight small islands in a lake, and the state wants to build seven bridges to connect them so that each island can be reached from any other one via one or more bridges. The cost of constructing a bridge is proportional to its length. The distances between pairs of islands are given in the following table.
Find which bridges to build to minimize the total construction cost.
Problem 15 (#2.3.30).If f and f◦g are one-to-one, does it follow that g must
be one-to-one? Justify your answer.
Chapter 5 Solutions
Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
Knowledge Booster
Similar questions
- Problem 1. Two DNA strands of length 100 (number of bases in the sequence) are given in DNA1.txt and DNA2.txt file. Find the longest common subsequence (LCS) between the two sequences using dynamic programming bottom-up (tabulation) approach. Submit your code to solve the problem. How much time (in seconds or milliseconds) is required by your computer to run the algorithm? Solve the same LCS problem using dynamic programming top-down (memorization) approach. Submit your code to solve the problem. How much time (in seconds or milliseconds) is required by your computer to run the algorithm. Which solution is faster and why? Discuss your solutions.arrow_forward4.1.1 Complete solution and answer only no need explanation Given three data points (1,6), (3,28), and (10, 231), What is the value of y at x = 2 if the function y = 2x2 + 3x + 1 passes through the three data points.arrow_forwardQ.) Do given c and d problem belowarrow_forward
- 2. (5.12 in 8e) answer each of the followig question. a) what does it mean to choose numbers "at random"? b) why is the rand function useful for simulating games of chance? c) why would you randomize a program by using srand? Under what circumstances is it desirable not to randomize? d) why is it often necessary to scale and/or shift the values produced by rand ?arrow_forwarda- For the (7, 4) cyclic Hamming code with generator polynomial g(X) = X³ + x² + 1, construct an (8, 4) extended Hamming code and list all the codewords. What is dmin for the extended code? b- An (8, 4) linear block code is constructed by shortening a (15, 11) Hamming code generated by the generator polynomial g(X) = X+ + X + 1. a. Construct the codewords of the (8, 4) code and list them. b. What is the minimum distance of the (8, 4) code?arrow_forwardComputer Science As a computer engineer you are required to do partial derivatives using numerical methods. Choose partial derivative problem with more than TWO (2) independent variables and solve using central difference techniques and compared with actual solutions by computing the relative error. Adopt multithreading in Python by spawning numerical difference solution for each independent variable and show performance gained compared to sequential approach (use Python time function to clock computation time). Use appropriate step sizes and adopt Richardson Extrapolation in ‘thread’ to improve the accuracy of central difference and tabulated results accordinglyarrow_forward
- 4. Look up the Pythagorean theorem if you are not already familiar with it. Use the following formula to solve for c in the formula: c = √a2 + b2. Use the proper functions from the cmath header file. Be sure to output the result..arrow_forward21. Take a careful look at Fig. 6-11(b). If D asks for one more unit, does this lead to a safe state or an unsafe one? What if the request came from C instead of D?arrow_forwardProblem 10arrow_forward
- VII.Let A = {2, 4, 6, 8}, B = {6, 9}, C = {4, 8}. Answer each of the following questions. Justify your answers. 1. Is B ⊆B?arrow_forwardWrite a C++ code for the given problem: Given two arrays X and Y of positive integers, find the number of pairs such that xy > yx (raised to power of) where x is an element from X and y is an element from Y. Input: M = 4, X[] = [2 3 4 5] N = 3, Y[] = [1 2 3] Output: 5 Explanation: The pairs for the given input are 21 > 12 , 31 > 13 , 32 > 23 , 41 > 14 , 51 > 15 . Expected Time Complexity: O((N + M)log(N)) Constraints: 1 ≤ M, N ≤ 105 1 ≤ X[i], Y[i] ≤ 103arrow_forward5. (a) Write a function that solves the general linear least-squares problem. The inputs to your function should be a vector of a values, a vector of measured y values, and an anonymous function that calculates a single row of the Z matrix. Inside your function, use the inputted anonymous function to create Z row-by-row, then use Z to create the normal equations. Solve these normal equations to obtain the computed coefficients that define the best-fit of your model. Your function should output these calculated coefficients. Again, include an error check that makes sure the input vectors are the same size. You may not use any built-in MATLAB functions to solve the normal equation. You can use any functions you have developed solves Ax = b via LU-decomposition is one option. e.g. a function you have that (b) Test your function in (a) to fit the following model to the given dataset (see belo y = a + bx (c) Test your function in (a) to fit the following model to the given dataset…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr