answersLogoWhite

0

Best case: O(n)

Worst case: O(n2)

Let's assume we're sorting data in an array of length n. Let's also assume that we're sorting in ascending order (low-high).

The worst case is that you will have the smallest value in the last space in the array. This means that it will move exactly once each pass towards the first space in the array. It will take n-1 passes to do this, doing n comparisons on each pass: O(n2)

The best case is that the data comes to us already sorted. Assuming that you have a smart implementation (which you should, because it's easy) which stops itself once a pass makes no changes, then we only need to do n comparisons over a single pass: O(n)

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What is the time and space complexity of the Quick Sort algorithm?

The time complexity of the Quick Sort algorithm is O(n log n) on average and O(n2) in the worst case scenario. The space complexity is O(log n) on average and O(n) in the worst case scenario.


What is the time complexity of quicksort algorithm?

The time complexity of the quicksort algorithm is O(n log n) in the average case and O(n2) in the worst case.


What is the worst case and best case time complexity of heapsort?

The best and worst case time complexity for heapsort is O(n log n).


What is the time complexity of quick sort algorithm?

The time complexity of the quick sort algorithm is O(n log n) in the average case and O(n2) in the worst case.


What is the memory complexity of quicksort algorithm?

The memory complexity of the quicksort algorithm is O(log n) in the best and average cases, and O(n) in the worst case.


What is the space complexity of quicksort algorithm?

The space complexity of the quicksort algorithm is O(log n) in the best and average cases, and O(n) in the worst case.


What is complex sort?

Time complexity Best case: The best case complexity of bubble sort is O(n). When sorting is not required, all the elements are already sorted. Average case: The average case complexity of bubble sort is O(n*n). It occurs when the elements are jumbled, neither properly ascending nor descending. Worst case: The worst-case complexity of bubble sort is O(n*n). It occurs when the array elements are needed to be sorted in reverse order. Space complexity In the bubble sort algorithm, space complexity is O(1) as an extra variable is needed for swapping.


What is the worst-case time complexity of quicksort?

The worst-case time complexity of quicksort is O(n2), where n is the number of elements in the array being sorted.


What is the worst case time complexity of heapsort?

The worst case time complexity of heapsort is O(n log n), where n is the number of elements in the input array.


What is the space complexity of quick sort algorithm?

The space complexity of the quick sort algorithm is O(log n) in the best and average cases, and O(n) in the worst case.


What is the space complexity of the Quick Sort algorithm?

The space complexity of the Quick Sort algorithm is O(log n) in the best and average cases, and O(n) in the worst case.


What is the worst case time complexity of heap sort?

The worst case time complexity of heap sort is O(n log n), where n is the number of elements in the input array.