Unformatted text preview: k , then n n = n n/2 × n n/2 . exp(a,b) var q:^celltype; begin if b=0 then return (1) else if b mod 2 = 1 then exp(a,b):= a*(exp(a,b div 2)) 2 else exp(a,b):=(exp(a,b div 2)) 2 end Then, exp(n,n) calculate n n , and the time complexity is O(logn). The program does not need to be the recursive one, but the recursive one is the most obvious. 6. Assume “a few” = O(1). Then insertion sort gives time=O(n) Assume “a few” # , then if heap sorts the random elements first and then merge with n the rest: time=O(n), space=O(n)....
View Full Document
This note was uploaded on 12/10/2009 for the course CAS 2c03 taught by Professor Janicki during the Spring '03 term at McMaster University.
- Spring '03