1.

What will be the recurrence relation of the code of recursive bubble sort?(a) T(n) = 2T(n/2) + n(b) T(n) = 2T(n/2) + c(c) T(n) = T(n-1) + n(d) T(n) = T(n-1) + cI have been asked this question in an interview.Question is taken from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (c) T(n) = T(n-1) + n

The best EXPLANATION: The recurrence RELATION of the code of recursive bubble sort is T(n) = T(n-1) + n. It can be solved by the method of SUBSTITUTION and is FOUND to be equal to n^2.



Discussion

No Comment Found

Related InterviewSolutions