Apply loop fusion or loop distribution to these code fragments as appropriate, Identify the technique you use and write the modified code.
a- Loop fusion-
for(i=0;i<N;i++){
z[i]=a[i]+b[i];
w[i]=a[i]-b[i];
}
b- loop distribution-
for(i=0;i<N;i++){
x[i]=c[i]*d[i];}
for(i=0;i<N;i++){
y[i]=x[i]*e[i];}
c-loop fusion,loop distribution:
for(i=0;i<N;i++)
{
for(j=0;j<M;j++){
c[i][j]=a[i][j]+b[i][j];}
for(j=0;j<M;j++){
x[j]=x[j]*c[i][j];}
for(j=0;j<M;j++){
y[i]=a[i]+x[j]}
}
Apply loop fusion or loop distribution to these code fragments as appropriate, Identify the technique you...
Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) cout << (j + k) << endl; } d. while (n > 1) { k += n *3; n = n / 2; } e. int temp = n; for (int j...
Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) cout << (j + k) << endl; } d. while (n > 1) { k += n *3; n = n / 2; } e. int temp = n; for (int j...
01) Write PIC24 assembly language equivalents for the Sollowing C code fragments. Assume variables u16 iul kal6 j.ul6 n are uintl6 variables, while uš p, u8 q, u8 rare uin variables 1. Code fragent 2. Code fragment . Code frapent (use place holders for if-body, else-body) if-body statements else-body statements 4. Code fragent (use place holders for if-body, else-body) if-body statements l else I else-body statenents 5. Code frapent (use place holders for loop-body) &. Code fragent (use place holders...
Exercises • Determine running time for the following code fragments: (a) a = b + c; d = a + e; (b) sum = 0; for (i=0; i<3; i++) for (j=0; j<n; j++) sum++; (c) sum=0; for (i=0; i<n<n; i++) sum++; (d) for (i=0; i < n-1; i++) for (j=i+1; j <n; j++) { tmp = A[i][j]; A[i][j] = A[j] [i]; A[j][i] = tmp; (e) sum = 0; for (i=1; i<=n; i++) for (j=1; j<=n; j+=2) sum++;
2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2. $s2. 2 subi $t1. st1. 1 bne t1. 0. LOOP DONE: LOOP: it st2. $0. stl beq t2. 0. DONE addi $s2. Ss2. 2 LOOP DONE: For the loops written in MIPS assembly in the above table, assume that the register Şt1 is initialized to the value of 10. What is the value in register $s2 assuming that $s2 initially has a value of...
Assume that arr[] is an array of 5 values. Write code within the FOR loop below so that it finds the min value in the array. You MUST use the x pointer within the FOR loop. It is the only pointer you can use. You are not allowed to made additional function calls or modify anything else within the function. Do not modify the FOR loop conditions or anything outside of the FOR loop. You must use complete C++ code...
Rewrite the following C++ code fragments. Your modified code should obey the following rules: • No global variables • No pass-by-reference and pass-by-pointer parameters (except arrays) • No iteration 1 Fibonacci int fib (int n) { if (n <= 1) return 1; int x = 1; int y = 1; int t; for (int i = 2; i <n; i++) { t = x; x = x + y; y = t; return x; 2 Min and max in an...
Compile the following C while loop into MIPS assembly code assuming the following register-variable mapping shown below. Also assume the array A holds integers.//$s0: A, $s1: I, $s2: j, $s3: x for(i=0; i<100; i++) {x=0; for(j = i + l; j < 100; j++) {x = x + A [j];} A[i] = x;}
05/0172019 Q1: (20) Choose one of these C code fragments and write it in PIC24 assembly form. if (u16 i< u16 k) |I True if((u 16-i <ul6k) && TAR (ul6j_u16_p)11 (16.9 !=0)) { if body Falttau 16-j != 80)) { if body else else else-body else-body f code rest of code s else.
05/0172019 Q1: (20) Choose one of these C code fragments and write it in PIC24 assembly form. if (u16 i
Use an algorithm that you would systematically follow to apply
the technique and solve each set of systems of linear
equations.
For example, you may select the technique of finding the
inverse of the coefficient matrix A, and then applying Theorem
1.6.2: x = A^-1 b. There are several ways that we have learned to
find A^-1. Pick one of those ways to code or write as an
algorithm.
Or another example, you may select Cramer’s rule. Within
Cramer’s rule,...