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
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.
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
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}
4. Given Pseudocode: Algorithm3(n): y = 0 for i = 1 to n do y =...
4. Given Pseudocode: Algorithm3(n): y = 0 for i = 1 to n do y = 1 while y < i2 do y=2y return y a. What's the output of Algorithm3(n) as a function of n? b. What's the running time of Algorithm3(n) as a function of n? Represent this as a summation. c. Prove the running time to be O(n log n).
Concern the following 16-bit floating point representation: The first bit is the sign of the number...
Concern the following 16-bit floating point representation: The first bit is the sign of the number (0 = +, 1 = -), the next nine bits are the mantissa, the next bit is the sign of the exponent, and the last five bits are the magnitude of the exponent. All numbers are normalized, i.e. the first bit of the mantissa is one, except for zero which is all zeros. 1. What's the smallest difference between two consecutive or adjacent numbers?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT