1 / 15

Computational Complexity

Computational Complexity. Size Matters!. Suppose there are several algorithms which can all be used to perform the same task. We need some way to judge the efficiency of the algorithms against each other.

engelbert
Download Presentation

Computational Complexity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computational Complexity Size Matters!

  2. Suppose there are several algorithms which can all be used to perform the same task. We need some way to judge the efficiency of the algorithms against each other. We can break the algorithms down into the basic steps, and then count how many steps there are in each. This is the computational complexity of the algorithm.

  3. The computation complexity is given in terms of the size of the problem. For example, XORing two 5 bit binary numbers will take 5 basic steps, but XORing two 100 bit binary number will take 100 basic steps. The algorithm used to XOR is the same in each case and its complexity is given in terms of the size of the binary numbers.

  4. The size of a numbern is defined to be the number of binary bits needed to write n in base 2. • We use b(n) to denote the size of n. Examples b(5) = b(1012) = 3 b(20) = b(101002) = 5 b(212) = b(4096) = b(10000000000002) = 13 What is b(0) ?

  5. If we XOR two binary numbers each of size b then we take b steps. • We say XORing has computational complexity of “order b” which is written O(b) • If we double the size of the problem – here the size of the numbers to be XORed, then we double the number of steps required and thus the time needed.

  6. Computational complexity is measured independently of the implementation. • The amount of time that is required to perform b basic steps will vary from computer to computer. • The important thing to note is that for an algorithm with complexity O(b), multiplying the size of the problem by X will have the effect of multiplying the time required by X as well.

  7. The computational complexity of adding two binary numbers is also O(b). • However, the computational complexity of multiplying two numbers is O(b2). If you double the number of bits in the numbers to be multiplied, then the time required quadruples because (2b)2 = 4b2

  8. Exponentiation(Raising to the Power) Suppose we want to compute x8 Method 1 Multiply x by itself 8 times x8 = x*x*x*x*x*x*x*x The total number of multiplications used is 8

  9. Method 2 Another approach would be to realise that x8 = (x4)2 = (x2)2)2 So we need to compute x2 (one mult.), then square that answer to get x4 (another mult.), finally square that answer to get x8(one more mult.) . We have used only 3 multiplications instead of 8.

  10. Suppose we need to compute x9. We can compute x8 and then multiply the answer by x (x9 = x8+1 = x8*x). A total of 4 multiplications. How about x13 ? 13=8+4+1 We can compute x8, multiply that answer by x4 (which we have already computed on the way to x8) and finally multiply that answer by x – a total of 5 multiplications.

  11. What is going on here? • Represent the power in binary (eg 13=8+4+1 = 11012) • Calculate x2 , x4, x8using successive squaring • Multiply together the answers which have a one in the binary power i.e., 13 = 8 + 4 +1 so we multiply x8 * x4 * x1

  12. Complexity of Method 2 • If the size of the power is b, then the number of multiplications will be at least b because that is the number of successive squaring multiplications required. • We also need to do up to b-1 other multiplications depending on how many 1’s there are in the binary representation of the power. • So the number of multiplications is between b and 2b.

  13. We have already seen that the order of complexity of multiplying two numbers together is O(b2). • We need to do between b and 2b multiplications, so the number of steps we do in total will be between b3 and 2b3. • We ignore constant values when talking about complexity and so say that our algorithm has order O(b3).

  14. Algorithm for exponentiationTo Compute xn Initialise y=1, u=x Repeat if n mod 2=1 then y=y*u n=n div 2 u=u*u Until n=0 Output y

  15. Why is complexity important with regards to cryptography? • The numbers we are working with are very big. Suppose b(n)=1000. Then the difference between an O(b) algorithm and an O(b2) algorithm is approx. 10002 = 106 steps. • Functions such as exponentiation are used a lot in cryptographic protocols and the protocol would be too inefficient to use if there were not an efficient method for exponentiation. • On the other hand, some cryptographic protocols rely on the fact that there is no efficient algorithm which could be used to break them.

More Related