This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: { 3.1. m = m * a } return m End Exp2( a,n ) Assumption: n is an integer ≥ 0, and a ≥ 1 1. If n = 0, then return 1 2. Else, return a * Exp 2( a,n1) End Exp3( a,n ) Assumption: n is an integer ≥ 0, and a ≥ 1 1. If n = 0, then return 1 2. Else 2.1. Let m = b n 2 c 2.2. Let x = Exp 3( a,m ) 2.3. Let y = x * x 2.4. If n is even, then return y 2.5. Else, return y * a End (a) Assume constant time complexities for basic operations (multiplication, addition, etc). Give the time complexities for the above two alogrithms in terms of n (in big O notation). (b) You may want to implement the above algorithms and see the running time of the algorithms for various values of n . 2...
View
Full
Document
This note was uploaded on 01/06/2012 for the course CS 3230 taught by Professor Sanjay during the Fall '10 term at National University of Singapore.
 Fall '10
 sanjay
 Algorithms

Click to edit the document details