What would be the worst case time complexity of the insertion sort algorithm, if the inputs are restricted to permutations of 1...n with at most a n inversions?
A
Θ(n1.5)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
Θ(n2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Θ(nlogn)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Θ(n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
Open in App
Solution
The correct option is DΘ(n) Insertion sort runs in O(n + f(n)) time where f(n) denotes number of inversions.
Therefore time complexity is Θ(n).