How to calculate algorithm time complex - algorithm

I am trying to multiple two big integer with Karatsuba algorithm.
I known that O(n) is time complexity and T(n) is worst-case time complexity.
Can some one please explain why:
T(n) = 4T(n/2) + O(n) is O(n^2)
And
T(n) = 3T(n/2) + O(n) is O(n^1.59)

T(n) = 4T(n/2) + O(n)
According to the Master theorem:
T(n) is O(n^log_2(4)) = O(n^2)
and
T(n) = 3T(n/2) + O(n)
is
T(n) = O(log_2(3)) ~ O(n^1,5849)
so you can round it to 1.590.

Related

Finding time complexity Big-Θ of this recursive formula involving floor function

I am trying to find the time complexity (Big-Θ) of this algorithm:
Recursion(n):
while n > 1:
n = floor(n/2)
Recursion(n)
I have found an upper bound of O(n) by considering the worst case which is when n is a power of 2.
However, I am having trouble finding a lower bound (Big-Ω) for this. My intuition is that this is Ω(n) as well, but I am not sure how to show this with the floor function in the way.
Any suggestions? Thank you!
EDIT: the main thing I'm not convinced of is that T(n/2) is equivalent to T(floor(n/2)). How would one prove this for this algorithm?
floor function performs its operation in constant time, O(1). Therefore you can ignore it/see it as a constant. Let's analyze the time complexity of the algorithm below:
T(n) = T(n/2) + 1 (floor operation)
T(n/2) = T(n/4) + 1
...
T(2) = T(1) + 1 --> T(1) = constant
T(n) = T(n/4) + 2
T(n) = T(n/8) + 3
...
T(n) = T(n/2^k) + k 2^k = n therefore k=log(n)
T(n) = T(1) + log(n)
T(n) = log(n)
We can conclude that T(n) ∈ θ(log(n)).

Calculate the time complexity of a reccurence relation, Big-Oh notation

I'm trying to find the Big-Oh of this recurrence relation:
T(N) = 4T(N/2) + N^2.
T(1) = 1
From the master theorem we can say T(n) = \Theta(N^2 log(N)) (see case 2).
The answer of the recurrence relation is :
O(N^2 log N)

Trying to understand complexity of this big0 notation

T(n) = n(T(n-1) + T(n-1)) + o(1) . The answer as per the book is o(n!) I am not able to come to this solution. Can someone give some guidance.
Okay, here's my take on this:
T(n) = n(T(n-1) + T(n-1)) + O(1)
T(n) = n(2T(n-1)) + O(1)
T(n) = nT(n-1) + O(1) // constants are not included in complexity. O(n + k) = O(k)
T(n) = nT(n-1)
This is a factorial complexity.

Expected running time value of a random algorithm

Given this algorithm, I am required to :
Find the recursion formula of the expected value of the running time.
Find the closest upper bound as possible.
I am actually a bit lost so if someone could help...
Recursive formula for worst case: T(n) = T(n/2) + n
Recursive formula for best case: T(n) = T(1) + n
Recursive formula for expected case: T(n) = T(n/4) + n
Worst case: 2n = O(n)
Best case: n = O(n)
Expected case: 4n/3 = O(n)
Some people here seem to be confused about the log(n) factor. log(n) factor would only be required if T(n) = 2T(n/2) + n i.e. if the function was called TWICE recursively with half the input.

Time complexity of one recursive algorithm

here we have an algorithm
T(n) = n-1 + T(i-1) + T(n-i)
T(1) = 1
How to calculate it's time complexity?
i is between 1 and n
I can recognise this as quick sort algorithm (randomized quick sort).
I am sure the question somehow missed the summation part.
Okay! you can use substitution method over here..check with O(n^2). you will get the idea that O(n^2) is the worst case time complexity.
The average case is a bit tricky. Then the pivot can be any element from 1 to n. Then analyse it. Here also you can apply substituin with T(n)=O(nlogn).
I think we should solve it like this
if i = 2 then we have
T(n) = n + T(n-2) = Theta(n^2)
if i = n/2 then we have
T(n) = n-1 + T(n/2 -1) + T(n/2) = Theta(n.logn)
then we have upper bound O(n^2) and algorithm is in order of O(n^2)

Resources