Question

In: Computer Science

Count the number of flops (floating point operations) in the following pseudocode: for i=1:n   for j=1:i    ...

Count the number of flops (floating point operations) in the following pseudocode:

for i=1:n  

for j=1:i    

for k=j:n      

y=y+aijxij    

end  

end

end

Solutions

Expert Solution

This question isn't really a matlab question. You can also apply brute force(checking every condition and add it) way of working it out.

Question.

for i=1:n  

for j=1:i    

for k=j:n      

y=y+aij * xij    

end  

end

end

1: The inner equation has two flops, so the k (j -> n) loop has 2(n-j+1) flops.

2: Now Move to j loop (1 -> i ):

summation of 2(n-j+1) i times in j loop ( here q = 2(n-j+1) ) 

 it helps to know the sum of q from 1 -> i is i(i+1)/2 and q^2 from 1 to i is i(i+1)(2i+1)/6.

The j loop is of 2(n-j+1) for j from 1 -> i, so it has 2i(n+1)-i(i+1)=2i(n+1/2)-i^2 flops.

3: The overall, or i, loop is a sum of 2i(n+1/2)-i^2, giving n(n+1)(n+1/2) - n(n+1)(2n+1)/6 = n(n+1)(2n+1)/3.

You can see that this is the same as the sum from 1 to n of 2i^2.

A way to check this, e.g. in matlab, is to set some n, and put f=0 at the start and replace the inner equation with f=f+2;, then the result will be f=n(n+1)(2n+1)/3.



Total flipflop : f=n(n+1)(2n+1)/3.

Related Solutions

Convert the following floating-point number (stored using IEEE floating-point standard 754) to a binary number in...
Convert the following floating-point number (stored using IEEE floating-point standard 754) to a binary number in non-standard form. 0100_0001_1110_0010_1000_0000_0000_0000
for (i=0; i<n; i++) for (j=1; j<n; j=j*2)    for (k=0; k<j; k++) ... // Constant...
for (i=0; i<n; i++) for (j=1; j<n; j=j*2)    for (k=0; k<j; k++) ... // Constant time operations end for end for end for Analyze the following code and provide a "Big-O" estimate of its running time in terms of n. Explain your analysis. Note: Credit will not be given only for answers - show all your work: (2 points) steps you took to get your answer. (1 point) your answer.
1. If you stored the following binary number (-0.000000100101) as a binary floating point number, what...
1. If you stored the following binary number (-0.000000100101) as a binary floating point number, what value would be STORED in the exponent section? Also convert A7.11 Hex value to floating point. 2. Number of bits saved using Huffman encoding. From the following characters used in a message with their associated frequency, use Huffman Coding as a compression technique. How many bits will be saved in the message? (Keep in mind that one character is one byte which consists of...
Write a Program(code) in Python that performs a large number of floating-point operations and an equal...
Write a Program(code) in Python that performs a large number of floating-point operations and an equal number of integer operations and compares the time required. Please attach an output.
3. IEEE Floating Point Representation What decimal number does the 32-bit IEEE floating point number 0xC27F0000...
3. IEEE Floating Point Representation What decimal number does the 32-bit IEEE floating point number 0xC27F0000 represent? Fill in the requested information in the blanks below. What is the sign of the number (say positive or negative): What is the exponent in decimal format: What is the significand in binary: What is the value of the stored decimal number in decimal (final answer): Credit will be given for your final answer in the blanks and the work shown below.
Assume that you have a 12-bit floating point number system, similar to the IEEE floating point...
Assume that you have a 12-bit floating point number system, similar to the IEEE floating point standard, with the format shown below and a bias of 7. The value of a floating point number in this system is represented as    FP = (-1)^S X 1.F X 2^(E-bias) for the floating point numbers A = 8.75 and B = -5.375. The binary representation of A is given as A = 0101 0000 1100 Show the hexidecimal representation of B.
Using the simple model for representing binary floating point numbers A floating-point number is 14 bits...
Using the simple model for representing binary floating point numbers A floating-point number is 14 bits in length. The exponent field is 5 bits. The significand field is 8 bits. The bias is 15 Represent -32.5010 in the simple model.
Given an array A[1..n] of integers such that A[j] ≥ A[i] − d for every j...
Given an array A[1..n] of integers such that A[j] ≥ A[i] − d for every j > i. That means any inversion pair in A differs in value by at most d. Give an O(n + d) algorithm to sort this array.
COMPUTER SCIENCE- FLOATING POINT REPRESENTATION: Hello, I completed a program for floating point representation (it can...
COMPUTER SCIENCE- FLOATING POINT REPRESENTATION: Hello, I completed a program for floating point representation (it can add and multiply floating point values in IEEE format). I already completed it, but I came back with 3 small errors. Can someone please fix them? I posted them at the bottom, here is the code: __________________________________________________________________________________________________________________________________ fp.java: // fp class public class fp {    // add function public int add(int a, int b) { FPNumber fa = new FPNumber(a); FPNumber fb =...
Convert the following number into 32bit IEEE 754 floating point representation. 0.000101
Convert the following number into 32bit IEEE 754 floating point representation. 0.000101
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT