hw 3 solutions

Upload: st57143

Post on 18-Jan-2016

215 views

Category:

Documents


0 download

DESCRIPTION

Algorithms solutions

TRANSCRIPT

1. Solution

It is assumed that the values for the constants c=2, d=2 and f(k)=kk logdc = k log22 = k 1 =k k logdc = f(k) and this can be solved using the case 2 of the master method solution and thus the final equation can be proved based on the below equation T(n) = (k logdc log2 k)= (k log2 k).

2. Solution

Specified problem can be solved using the below processT(2n)=2N(2n)+ 1 or N(2n)=N(2n/2)+ 1Replace function is used to replace the corresponding values i.e. N(2n) to S(n) and now the new relation established in this context is as show belowS(n)=2S(n/2)+ 2nNow the constant values of c=2 and d=2 and Q(n) =1 are considered and substituted and the respective equation is as shown belown logdc = n log22 = n 1 =n=log xn logdc Q(n) and this problem I solved using the Master method case 1

3. Solution

Iterative method can be used to solve this problem and the respective solution is as shown belowN(t)=2*N(t-1) + tN(t)=2* (2*N(t-2) + t-1) + t = 22*N(t-2) + t +2(t-1) N(t)= 22* (2N(t-3)+t-2) ) +t+2(t-1)= 23*N(t-3) + t +2(t-1)+22(t-2).N(t)=2x*N(t-x) + t +2(t-1)+22(t-2)++2t-1(t-(x-1)) N(t)= 2t-1*N(t-(t-1)) + t +2(t-1)+22(t-2)++2t-1(t-(t-2)) Once the series is solved using the sequential value the final output will be derived

4. Solutions

(1)To solve this equation it is assumed that the constant values c=2, d=2 and f(k)=kk logdc = k log22 = k 1 =k k logdc = f(k); this is applied based on the master method case 2 and thus the final equation is N(k) = (k logdc log2 k)= (k log2 k).

(2)Below is the solution to this question based on the equations as explained aboveN(k)=N(k-1)+(1)

(3)Solution for this equation is as given below

N(k) = N(bkn/2f) + 1< a lg(k/2) + 1 (using the IH)= a(lg k lg 2) + 1= a lg k (a 1)< a lg k om a > 1

(4)

Solution for this equation is as given below

T(n) = 4T(n/2) + n3. Here, a = 4, b = 2 and f(n) = n3 which gives nlogb a = n2. This timef(n) = (n2 + ) if = 1, if 4f(n/2) cf(n), i.e., if 4(n/2)3 cn3, which is true for, e.g.,c = 1/2. Thus, T(n) = (n3).

(5)

Similar calculations are done to this equation as well and the solution is as given below

T(n) = T(2m) = S(m) = O(lgm) = O(lg lg n).

(6)

Similar calculations are done to this equation and the solution using the Master method is as shown below

< c lg n om c > 1

(7)

Similar calculations are done to this equation and the solution using the Master method is as shown below> cn lg n if c < 1

(8)Similar calculations are done to this equation and the solution using the Master method is as shown below< dn2 en if e > c

(9)Similar calculations are done to this equation and the solution using the Master method is as shown below

dn2 (2adn 2da2 cn)

(10)Similar calculations are done to this equation and the solution using the Master method is as shown below

T(n) = (n logba log2 n)= (log2 n).