Download presentation

Presentation is loading. Please wait.

Published byJason Rodgers Modified over 2 years ago

1
1 Computational Complexity Size Matters!

2
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
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
4 The size of a number n 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(101 2 ) = 3 b(20) = b( ) = 5 b(2 12 ) = b(4096) = b( ) = 13 What is b(0) ?

5
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
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
7 The computational complexity of adding two binary numbers is also O(b). However, the computational complexity of multiplying two numbers is O(b 2 ). If you double the number of bits in the numbers to be multiplied, then the time required quadruples because (2b) 2 = 4b 2

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

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

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

11
11 What is going on here? Represent the power in binary (eg 13=8+4+1 = ) Calculate x 2, x 4, x 8 using successive squaring Multiply together the answers which have a one in the binary power i.e., 13 = so we multiply x 8 * x 4 * x 1

12
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 1s there are in the binary representation of the power. So the number of multiplications is between b and 2b.

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

14
14 Algorithm for exponentiation To Compute x n 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
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(b 2 ) algorithm is approx = 10 6 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.

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google