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.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
Using functional C++ programming, not OOP
Given set A = {23, 56, -7, 6, 0, 75, 2.7, -3.6, 8, -4.77, 43, 678} and set B = {5, 8, 46, -98, 46}
a. Using merge sort approach, sort the numbers in set A and B jointly.
b. Using RAM diagrams, show the values of parameters that are passed between the partition() function and sort() function.
Consider the following list of elements (M-2) 18, 40, 16, 82, 64, 67, 57, 50, 37, 47, 72,14, 17, 27, 35Using quicksort algorithm, Use pivot as the median of the first, last, and middle elements of the list.a. What is the pivot?b. Give the resulting list after one call to the partition procedure.
(Data structure and algorithm in c++)
Q2: Besides the while-loop in Q1, I want to implement a 2nd while-loop running in parallel with the first
while:
while(1) {
wt(1);
XX);
}
However, on an MCU there is no parallelism. (For ex., on Arduino I can define only one loop() function.)
Write a single while that does the job of both whiles.
(a) Write it in a procedural style.
(b) Write it the super-loop style (state-machine with fixed heartbeat).
Chapter 5 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Knowledge Booster
Similar questions
- Problem Description Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is alreadysorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum.Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j .Example: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3).Requirement Design should be based on divide and conquer.Running time should NOT be worse than .Must use recursion to solve the subproblems. Input Specification Your program should read from an input file, which starts with a line indicating the number of test cases.Each of the following lines indicates a test case, and each test case includes a sequence of numbers(separated by spaces) for which you need to count inversions. Sample Input 32 4 1 3 51 2 4 8 9 3 5 6 1 20 6 4 5Output Specification For each test case, print one line with a format of The sequence has ? inversions in…arrow_forward(1) Use perf_count and the other ideas from 8.1 above to generate a list of data, where the ith entry is the time tm(i) necessary for merge-sort to sort lists of randomly chosen elements of length 2¹ for i = 1, ..., 10. (2) Plot tm(i) against 2¹ on a loglog plot. Briefly explain (as a comment) what the graph says about merge- sort's speed, using big-O notation. (3) Write a function insertionsort (somelist) that applies the insertion sort algorithm described in lectures to sort a list. (You should use the pop and insert commands as described in the lecture notes.) (4) Use this to find the times tỉ(i) for lists of the same length as in (1). Add tr(i) to your graph (on the same axes as above), and write a comment on-what this says about the speed of insertion sort, in big O notation. (5) Write a function countingsort (mylist) which implements counting sort for lists of non-negative integers, using the algorithm described in lectures. (6) How efficient is countingsort compared to the other…arrow_forwardUse the Dynamic Programing approach to align the following 2 sequences. You must use the recursive Opt relationship and complete the array used to find the optimal alignment. х: А САС y: САА The penalty for a mismatch is 1. The penalty for a gap is 2. The penalty for a match is 0.arrow_forward
- Using functional C++ programming, not OOP Given set A = {23, 56, -7, 6, 0, 75, 2.7, -3.6, 8, -4.77, 43, 678} and set B = {5, 8, 46, -98, 46} a. Using q sort approach, sort the numbers in set A and B jointly. b. Using RAM diagrams, show the values of parameters that are passed between the partition() function and sort()arrow_forwardProblem_#05] Using a Karnaugh map, simplify the expressions below: (а) АВС + AВС + АВС + АВС (b) AC[B + B(B + C)] (c) DEF + DEF + DEFarrow_forwardLet M(m,n) denote the number of comparisons required to merge two sorted lists of sizes m and n. a) Derive an "information theoretic" lower bound on M(m,n). b) Find an interesting relation between M(m,n) and the analogous function S defined for sorting. Use this relation to derive a lower bound for M(m,n) in terms of S. (Hint: Start with an upper bound on S(m+n).arrow_forward
- Question 8: (a) ' Implement the Merge function in Python. (b) Implement the MSort function in Python. (c) Implement the Partition function in Python. (d) Implement the Qsort function in Python. Test your functions with the below code. #Testing Sorts import random for x in range (0, 10) : L = [random.randint (0, 100) for k in range (0, 10) ] print ("Merge Input:", L) L = msort (L) print ("Result after Merge Sort:", L) x in range (0, 10) : L = [random.randint (0, 100) for k in range (0,10) ] print ("Quick Sort Input:", L) qsort (L, 0, len (L) -1) print ("Result After Quick Sort:", L)arrow_forwarddiscrete mathematics (a) Apply the bubble sort to the following list and write the modified list in every cycle [6, 12, 8, 11, 15, 14, 17, 2, 18, 7] (you may stop after it is fully sorted). (b) Merge the following two sets and write the merging list in every iteration [3, 5, 6, 8, 10, 11, 15] and [4, 7, 9, 13, 17]arrow_forward(g) get_total_crimes_by_type(adict, 2Dlist) takes a dictionary (crime_dict) and a 2D-list (database), and returns another dictionary whose keys are the crime types l a (i.e., values of crime_dict), and values are the total number of crimes of those types reported in the database. See the sample output for examples. total_crime = get_total_crimes_by_type(crime_dict, database) display_dict(total_crime) Arson - 10 Break and Enter - 621 849 Fraud Mischief - 943 Possession / Trafficking Stolen Goods Theft $5000 and Under - 4793 - 38 Theft - Motor Vehicle - 168 Theft Over $5000 - 96 Page 6 of 10 Assignment # 4 Due: Nov. 27th 10:00 PM EST (h) get_total_crimes_by_type_and_year(adict, (crime_dict) and a 2D-list (database), and returns another dictionary like the previous function with year-wise break down. More precisely, the keys of this resulting dictionary are the crime types, and the values are some 2D-lists containing elements like this - [a unique Year, the total number of crimes of this…arrow_forward
- Use Figure 10.8 as an example to show how to apply the binary search approach to a search for key 10 and key 12 in the list [2, 4, 7, 10, 11, 45, 50, 59, 60, 66, 69,70, 79].arrow_forwardThe following Snippet of Matlab code will produce an error when executed: Show/hide Code Snippet 3 123 45 2 4 898 5 6 7 8 end 9 adder = 10 for k= 3:0.5:3 0; V adder = adder+k; v = [v; adder]; Add a single line of code to Code Snippet 3 so that it produces a column vector v that stores the consecutive values of adder as they are calculated inside the for loop.arrow_forwardWrite a report in which you discuss and compare your Gauss elimination and Gauss-Jordan programs. Gauss elimination #include<stdio.h> int main ( ) { int i, j, k, n; float A[20] [20], c, x [10], sum=0.0; printf("\Enter the order of matrix: "); Sacnf("%d,&n); prinf("\n Enter the elements of augmented matrix row-wise: \n\n"); for(i =1; i<=n; i++) { for(j=1; j<(n+1); j++) { printf("A[%d][%d] : ", i, j); scanf("%f", [i][j]); } } for(j=1; j<n; j++) { for(i=1; j<n; i++) { if(i>j) { c=A[i][j]/A[j][j]; for(k=1; k<=n+!; k++) { A[i][k] = A[i][k]-c*A[j][k]; } } } } x[n]= A[n] [n+1]/A[n][n]; for(i=n-1; i>=1; i--) { sum=0;…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