Alex. Gerbessiotis 01/24/2025 (c) All rights reserved. JANUARY 2025. ---------------------------------------- Homework 1 solution key ------------------------- Q1. a: 2 b: 1 c: 4 d: 3 Q2. YES input is x t1 = x**2 1st t2 = t1 * x = x**3 2nd t3 = t1 * t2= x**5 3rd t4 = t3 * t1= x**7 4th t5 = t4 * t4= x**14 5th t6 = t5 * t5= x**28 6th t7 = t6 * t6= x**56 7th t8 = t7 * t4= x**63 8th Q3. (a) T(n)=Theta(n) , (b) T(n) = O(lgn), (c) T(n) = Theta(n) . Q4. 63n [Total 7n+11n+17n+28n=63n] 3n,4n,10n, 5n,6n, 7n 11n 17n 28n Q5. little omega , littleomega, little o, little o, theta, little o Q6. a. T(n)=Theta(n) b. S(n)=Theta(1) (See Problem 20 of Subject1) Q7. (a) T(n)=Theta(n*lgn) Dup(X,n) [See Problem 13 of Subject 1(Appendix)] 1. Y=MergeSort(X,n); 2. for(i=0;i C(n) =nlgn/2 In the last iteration we have < 1, ... , n/2> To merge them we need only n/2 comparisons A recursion tree per class derives the result. (we just replace the node values eg n-1 by n/2.) Q9. 26, Justification: Use binary search with 2*lg(8192) = 2*13=26 comparisons (at most) Q10. a. T(n) = n lgn +16n . A=1,B=16, C=0 b. T(n) = 2n-4 D=E=0, F=2, G=-4 c. T(n) = 2 n lgn-2n K=2, L=-2,M=0 -------------------------------------------------------------------- Date created 01/23/2025 @ 10:01 Date last edited 01/24/2025 @ 11:25