wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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
Θ(n log n)
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).

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon