Question: ( a ) ( 1 0 0 pts ) Consider the following algorithm, and assume we have a function log 2 ( x ) which
a pts Consider the following algorithm, and assume we have a function logx which calculates
floorlog
x in Theta log x time. Describe what function g computes on input positive integers a and
b determine a tight Theta bound on its runtime, and argue that it the runtime correct.
: function ga b
: t
: s
: lgb logb
: for i to lgb do
: if b t t then
: s a t
: t
: return s
b pts Modify the algorithm above into a function ga b which computes powa b You can receive
up to points for a Theta b algorithm and points for a Theta log b algorithm.
cpts Give an algorithm which computes logb on input positive integer b in Theta log b time, and argue
that both the algorithm and the runtime are correct.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
