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.

Slides:



Advertisements
Similar presentations
Chapter 5: Control Structures II (Repetition)
Advertisements

Slide 1 Insert your own content. Slide 2 Insert your own content.
Chapter 4 Computation Bjarne Stroustrup
Factors, Primes & Composite Numbers
Dynamic Programming Introduction Prof. Muhammad Saeed.
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Multiplying monomials & binomials You will have 20 seconds to answer the following 15 questions. There will be a chime signaling when the questions change.
0 - 0.
How To Multiply Fractions
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Teacher Name Class / Subject Date A:B: Write an answer here #1 Write your question Here C:D: Write an answer here.
Addition Facts
Multiples and Factors Lesson 4.1.
RSA.
Modular Arithmetic Several important cryptosystems make use of modular arithmetic. This is when the answer to a calculation is always in the range 0 –
Zabin Visram Room CS115 CS126 Searching
CS4026 Formal Models of Computation Running Haskell Programs – power.
Automata Theory Part 1: Introduction & NFA November 2002.
HOW TO MULTIPLY FRACTIONS
Choose level of difficulty Brian wants to invest £ for one year. His bank offers two plans. Plan A Annual Booster: 6·5% per year, with the interest.
Lecture 11: Algorithms and Time Complexity I Discrete Mathematical Structures: Theory and Applications.
Monika Gope Lecturer IICT, KUET
Computing functions with Turing machines
Chapter 23 Minimum Spanning Tree
DIVISIBILITY, FACTORS & MULTIPLES
5.9 + = 10 a)3.6 b)4.1 c)5.3 Question 1: Good Answer!! Well Done!! = 10 Question 1:
Factors, Prime Numbers & Composite Numbers
HOW TO COMPARE FRACTIONS
Adding and Subtracting Rational Expressions (cont.)
Twenty Questions Subject: Twenty Questions
Created by Susan Neal $100 Fractions Addition Fractions Subtraction Fractions Multiplication Fractions Division General $200 $300 $400 $500 $100 $200.
Introduction Exponential equations are equations that have the variable in the exponent. Exponential equations are found in science, finance, sports, and.
Binary Lesson 3 Hexadecimal. Counting to 15 Base Base Base 16 Base Base Base 16 Two Ten (Hex) Two Ten (Hex)
Addition 1’s to 20.
Test B, 100 Subtraction Facts
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
Addition, Subtraction, and Multiplication of Polynomials
Complexity Analysis (Part II)
18-Dec-14 Pruning. 2 Exponential growth How many leaves are there in a complete binary tree of depth N? This is easy to demonstrate: Count “going left”
Bottoms Up Factoring. Start with the X-box 3-9 Product Sum
MA 1128: Lecture 13 – 10/27/14 Rational Expressions.
Introduction to Recursion and Recursive Algorithms
Lecture 16 Complexity of Functions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Order of Operations And Real Number Operations
Year 3 Objectives: Number NUMBER AND PLACE VALUE Objective 1: Read and write numbers up to 1000 in numerals and words Read and write all numbers to 100.
1 Efficient algorithms on sets of permutations, dominance, and real-weighted APSP Raphael Yuster University of Haifa.
12-Apr-15 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
Count to 20. Count reliably at least 10 objects. Use ‘more’ and ‘less’ to compare two numbers. Count reliably at least 10 objects. Estimate number of objects.
CSE115/ENGR160 Discrete Mathematics 03/13/12 Ming-Hsuan Yang UC Merced 1.
Great Theoretical Ideas in Computer Science.
PowerPoint A3 L4 Refine and use efficient written methods to multiply T U × T U.
Arithmetic.
COMPSCI 102 Introduction to Discrete Mathematics.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
3 x 5 means… 3 “lots of” 5 3 x 5 means… 3 “lots of” = 15.
Decimal Number System We are used to the decimal number system which is a positional number system The decimal number 4386 represents the value: 41000.
Multiplication is the process of adding equal sets together = 6 We added 2 three times.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Great Theoretical Ideas in Computer Science.
Fast Exponentiation (3/31) What is the most efficient way to compute (mod 32591)? We will need an efficient algorithm in order to do “RSA cryptography”,
Complexity 20-1 Complexity Andrei Bulatov Parallel Arithmetic.
9.1 Primes and Related Congruence Equations 23 Sep 2013.
Remarks on Fast Exp (4/2) How do we measure how fast any algorithm is? Definition. The complexity of an algorithm is a measure of the approximate number.
Copyright © Zeph Grunschlag, RSA Encryption Zeph Grunschlag.
Recursion ● Recursion or Iteration ● A Common Recursive Design Pattern ● Computing factorials ● Searching a filesystem tree ● Faster exponentiation ● Slow.
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 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 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(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 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 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 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 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 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 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 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 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.