Consider the following algorithm weirdproc on lists:
weirdproc (x) = shalf (x) + weirdproc ( fhalf(x) )
Suppose that shalf, fhalf, and + have time complexities that are linear with re-
spect to the size of the inputs. Write down an expression for the time complexity of
weirdproc for this case and determine its asymptotic solution.
I have this solution from my lecturer :
I dont understand how he got this line: O(n) + O(n) + T(n/2) + O(n)
and I dont understand why there are so many Tshalf's and Thalf's in the line above that?
Any help would be great as I have a test covering big O notation tomorrow
weirdproc (x) = shalf (x) + weirdproc ( fhalf(x) )
Suppose that shalf, fhalf, and + have time complexities that are linear with re-
spect to the size of the inputs. Write down an expression for the time complexity of
weirdproc for this case and determine its asymptotic solution.
I have this solution from my lecturer :
if x, y are lists of length O(n) then Tshalf(x), Thalf(x), T((x)(+)(y)) are all O(n) let T(n)= time taken to execute weirdproc on x, |x| = n Then T(n) = Tshalf(x) + Thalf(x) + weirdproc(fhalf x) + Tshalf(x) (+) weirdproc(fhalf x) =O(n) + O(n) + T(n/2) + O(n) =O(n) + T(n/2) so T(n) is O(n)
I dont understand how he got this line: O(n) + O(n) + T(n/2) + O(n)
and I dont understand why there are so many Tshalf's and Thalf's in the line above that?
Any help would be great as I have a test covering big O notation tomorrow