answersLogoWhite

0


Best Answer

Quick sort is not stable, but stable versions do exist. This comes at a cost in performance, however.

A stable sort maintains the order of equal elements. That is, equal elements remain in the same order they were input. An unstable sort may change the order. In some cases, the order of equal elements is of no consequence, but when two elements with different values have the same sort key, then order can be important.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Yes. If you are having problems do a manual bounds check. Also ensure that the user supplied function is not causing problems.

No. While its average cost if O(nlogn), its worst case cost is O(n2)

Ok someone is taking computer science. Cost has nothing to do with stability (from the computer science aspect) but everything to do with the pivot point as far as quicksort is concerned. Depending on how the pivot point is implemented dictates if quicksort is stable or not. Stable or not quicksort is a good all round sort routine, usually not the quickest or slowest. The speed of any sorting algorithm is dependent on what data the algorithm is required to sort and also the number of elements to be sorted.

It should be noted that the qsort function (usually assumed to be quick sort) does not necessarily implement the quicksort algorithm. The algorithm behind qsort is up to the library manufacturer.

From a practical standpoint with the average program cost is not the issue. Cost becomes an issue if there are performance problems. Performance problems can (usually) be kept at bay by sorting pointers (4 bytes) to data rather than sorting data (that can be very big).

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

The Quick Sort Method, however fast on average, has a bad worst case scenario. If for instance the list you sort is already sorted or oppositely sorted, the time for Quick Sort may be n*n in stead of n*log(n) - which in effect makes it as slow as the most simple sort method, Bubble Sort. Even when programmers change the routine so that exactly these worst cases will not occur, there will always be other possible lists that will slow down the Quick Sort.

Merge Sort, which is also n*log(n), does not have this worst case scenario. On average it's hardly slower (if at all) than Quick Sort, but it's far more stable in keeping that speed at all times.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Quick Sort is an "average" performing sorting algorithm; there are better algorithms out there, but it is considered the best of the "learner's algorithms" (generally implied to be quick sort, bubble sort, selection sort, and gnome sort). It has a medium-length average sorting time, which is faster than bubble sorting and gnome sorting, but also has a medium-length best-case sorting time, with bubble sorting and gnome sorting beating it speed-wise. It also has a higher memory overhead than in-place swapping algorithms such as bubble sort and gnome sort.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why is quick sort and merge sort called stable algorithms?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you sort an array of numbers?

Use a sorting algorithm. There are a bewildering number of sorting algorithms, both stable and unstable. To sort numbers, an unstable sort suffices. The algorithm you use will depend on how many numbers need to be sorted (a small or a large set), however a hybrid algorithm (a combination of two or more algorithms) can cater for both. Introsort (unstable) and timsort (stable) are the two most common hybrid sorting algorithms.


If quick sort and merge sort have same elements then what will be the complexity of both algorithms?

quicksort should be O(n^2), but merge sort should be O(nlogn). but if you can modify partition algorithm with checking all values same in array from p to r, it could be O(nlogn).


Which is the easiest sorting method?

There are generally eight sorting algorithms that are studied in school by computer science students. They are as follows: insertion, bubble, quick, quick3, merge, shell, heap, and selection sorting. There are different types of sorting algorithms. One would be considered good if it is accurate and efficient. Different types of sorting includes; sequential, ascending, and descending.


Who is better quick sort or merge sort?

Statistically both MergeSort and QuickSort have the same average case time: O(nlog(n)); However there are various differences. Most implementations of Mergesort, require additional scratch space, which could bash the performance. The pros of Mergesort are: it is a stable sort, and there is no worst-case scenario. Quicksort is often implemented inplace thus saving the performance and memory by not creating extra storage space. However the performance falls on already sorted/almost sorted lists if the pivot is not randomized. == ==


Limitations of merge sort and quick sort?

Comolexity Not efficent big data

Related questions

What are the types of sort algorithms?

insertion,bubble,quick, quick3, merge, shell,heap, selection sorting


How do you sort an array of numbers?

Use a sorting algorithm. There are a bewildering number of sorting algorithms, both stable and unstable. To sort numbers, an unstable sort suffices. The algorithm you use will depend on how many numbers need to be sorted (a small or a large set), however a hybrid algorithm (a combination of two or more algorithms) can cater for both. Introsort (unstable) and timsort (stable) are the two most common hybrid sorting algorithms.


If quick sort and merge sort have same elements then what will be the complexity of both algorithms?

quicksort should be O(n^2), but merge sort should be O(nlogn). but if you can modify partition algorithm with checking all values same in array from p to r, it could be O(nlogn).


Which is the easiest sorting method?

There are generally eight sorting algorithms that are studied in school by computer science students. They are as follows: insertion, bubble, quick, quick3, merge, shell, heap, and selection sorting. There are different types of sorting algorithms. One would be considered good if it is accurate and efficient. Different types of sorting includes; sequential, ascending, and descending.


Did Fleet Financial and Quick and Ready merge?

Fleet Financial and Quick and Ready merged


Who is better quick sort or merge sort?

Statistically both MergeSort and QuickSort have the same average case time: O(nlog(n)); However there are various differences. Most implementations of Mergesort, require additional scratch space, which could bash the performance. The pros of Mergesort are: it is a stable sort, and there is no worst-case scenario. Quicksort is often implemented inplace thus saving the performance and memory by not creating extra storage space. However the performance falls on already sorted/almost sorted lists if the pivot is not randomized. == ==


Why quick sort better than merge sort?

it has less complexity


Limitations of merge sort and quick sort?

Comolexity Not efficent big data


What is is it when you only give it a quick clean in a horses stable?

To "skip out".


What are the different types of sorting?

insertion,bubble,quick, quick3, merge, shell,heap, selection sorting


What are the different types of algorithm?

insertion,bubble,quick, quick3, merge, shell,heap, selection sorting


Is there a quick way on WikiAnswers to weed out all the questions that are exactly the same?

Currently, the ways to merge duplicate questions (that differ immaterially in content) are not as quick as they could be. A feature is planned whereby you could search for specific keywords and edit (and merge) questions without loading separate pages for each question.