Algorithms Mid-1 3
Algorithms Mid-1 3
Algorithms Mid-1 3
For each part in this question, you are required to analyze the given functions T(n) and
answer the given question.
a) For the following function f(n), find a function g(n), such that f(n) = θ (g(n))
[Hint: For part a you have to provide the constants 𝑛 , 𝑐 , 𝑐 ]
𝑻(𝒏) = (𝟏𝟎𝟎𝟎)𝟐𝒏 + 𝟒𝒏
𝒏 𝟒𝒏
b) Solve the recurrence relation 𝑻(𝒏) = 𝑻 +𝑻 + 𝒏, where 𝑇(1) = 1
𝟓 𝟓
𝒏
c) Solve the recurrence relation 𝑻(𝒏) = 𝟐𝟓𝑻 + 𝒏𝟐 , where 𝑇(1) = 1
𝟓
2 𝑖𝑠 𝑂(2 )
4 𝑖𝑠 𝑂(2 )
Let A[1..n] be an array of n distinct numbers. If 𝑖 < 𝑗 and 𝐴[𝑖] < 𝐴[𝑗] then the pair (𝑖, 𝑗) is
called a compatibility of A. Design an algorithm that determines the number of
compatibilities in any permutation on n elements in O(𝑛 log 𝑛) worst case time. (Hint:
Modify merge sort.)