Master method algorithm analysis of pseudocode -


how find c/d constant used in master theorem examining pseudo-code?

fastpower(a,b) :          if b = 1           return       otherwise           c := a*a           ans := fastpower(c,[b/2])       if b odd           return a*ans       otherwise return ans  end 

firstly, need find recurrance relation: t(n) = t(n/b) + o(d) + o(c) o(d) time takes divide problem subproblems, o(c) time takes recombine subproblems answer, number of subproblems, , n/b size of subproblems. then, once have recurrence can analyze using master theorem.

in algorithm, believe there 1 subproblem of size n/2, 1 , b 2. time dividing o(1) , time recombining o(1) assuming analysis not in terms of bit operations.

using master theorem, o(1) = Θ(nlog21) therefore total runtime Θ(nlog21 log n) = Θ(log n)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -