



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Tutorial Problems
O(1)
O (log n) time
The basic part here is NOT using the complete data, and reducing the problem side in every iteration
O(n) time
And here too you can find a million more such examples..... In a nutshell, all Brute Force Algorithms that requires linearity, are based on O(n) time complexity
O(nlogn) time
O(n log n): quick or mergesort (On average) Merge Sort Heap Sort Quick Sort Certain Divide and Conquer Algorithms based on optimizing O(n^2) algorithms
O(n^2 ) time
Q.No 1
For each of the following algorithms, indicate i. a natural size metric for its inputs; ii. Its basic operation; iii. Whether the basic operation count can be different for inputs of the same size: a. computing the sum of n numbers b. computing n! c. finding the largest element in a list of n numbers d. Euclid’s algorithm
Solution: The answers are as follows. a. (i) n; (ii) addition of two numbers; (iii) no
b. (i) the magnitude of n, i.e., the number of bits in its binary representation; (ii) Multiplication of two integers; (iii) No
Q.No 3
What is the worst-case complexity of the each of the following code fragments?
Solution:
a)
int recursive (mt n) { if (n == 1) return (1); else return (recursive (n-1) + recursive (n-1)); }