When deriving a recurrence for a divide-and-conquer algorithm (that is a recursive algorithm) you are to make explicit the costs of every part of the algorithm especially the cost of dividing, conquering (recurring), and combining, and relate these costs to the relevant parts of the algorithm.
When you derive tight asymptotic bounds Θ(...), use the Master Theorem where applicable; otherwise, first state why it is not applicable and then use any other relevant method or theorem (for example, guess the answer and prove by induction). In any case, always show all the details of your reasoning.
Give a recurrence for the running time T of the power x k function below, which returns x^k for any integer x and natural number k. State any assumptions you make.
fun power x 0 = 1 | power x k = x * power x (k-1)Derive a tight asymptotic bound for T.
Give a recurrence for the running time T' of the power' x k function below, which also returns x^k for any integer x and natural number k. State any assumptions you make.
fun power' x 0 = 1 | power' x k = let val p = power' x (k div 2) in if (k mod 2) = 0 then p * p else x * p * p endDerive a tight asymptotic bound for T'. Discuss the results.
Examples and counter-examples:
parenthesised "((a+b) * (c-d))" = true
parenthesised "((a+b * (c-d))" = false
parenthesised "(a+b)) * ((c-d)" = false
parenthesised "(a[(b+c) * d] + e) * f" = true
parenthesised "(a[(b+c) * d) + e] * f" = false
parenthesised "({ab} [+b(c *)])" = true
Hint: The explode function returns the
character list corresponding to a string.