Give the Best, Average and Worst case examples and complexities of the following algorithms:
a)Insertion Sort
b) Quick Sort
c) Bucket Sort
Ans:
Insertion Sort
a)Best Case:O(n)
Eg: [1,2,3,4,5]
(The best case input is an array that is already sorted)
b)Average Case:O(n2)
Eg: [5,4,3,2,1]
c) Worst Case:O(n2)
Eg: [3,2,1,5,4]
(The simplest worst case input is an array sorted in reverse order.)
Please answer for Quick and Bucket Sort
No comments:
Post a Comment