What is QuickSort

Ads
 

What is QuickSort

Hi,

What is QuickSort and how it can be implemented in Java?

Thanks

View Answers

April 20, 2021 at 2:05 PM

Quick Sort In Java. The Java developers might choose to use the built-in QuickSort implementation or another one that is much, much much faster. This article does not tell you in which way Java implements QuickSort. It just tells you how to use it.

Why implement QuickSort?

QuickSort is a good, fast sorting method, it simply sorts the string in no arbitrary order, and there is no special code or anything to run on each character. It's fast.

The main disadvantage of QuickSort is that the number of comparisons between the string and each element is too high. Each comparison is potentially O(1), which is the worst possible solution in comparison. This problem is easily solved by using a slower sorting algorithm like an Ordinal or Radix sort instead.

How is QuickSort implemented?

QuickSort uses the Java.sort() API to sort the string, as well as a Java.quicksort() method to sort it quickly.

The best way to implement QuickSort is to use the standard implementation. You can see where this is going?

If you implement QuickSort yourself then you can still use the Java.sort() and Java.quicksort() methods (as they are used directly) to speed up the implementation, but this is more of a "you should know about what you're doing" than a good thing.

So what does QuickSort do?

QuickSort performs the following tasks in a very short time:

Sorts the string using a descending sort (this is called sorting in descending order, it is also called String Sort). The descending kind is used primarily in cases where the sorting is more efficient than trying to sort it based on the previous character, or where there is a very significant difference for the previous character between the new and the old string, in which case the standard sorting algorithm would not suffice (i.e. when the input string is longer than a string of this size).

The descending kind is used primarily in cases where the sorting is more efficient than trying to sort it based on the previous character, or where there is a very significant difference for the previous character between the new and the old string, in which case the standard sorting algorithm would not suffice (i.e. when the input string is longer than a string of this size). Creates a sorted array of the string element values.

Sorts each element in the sorted array and returns the new sorted array.

Sorts a string in one run. In other words, the implementation counts the number of comparisons made and calculates the difference between the previous character and the new character.

Sorts a string in one run.

Sorts a string in multiple runs. As a consequence, the number of comparisons is O(N).

Sorts a string in N run.

In other words, when the original string is a list of values of length N, the implementation does an O(log N) comparison for each value of length N. A list of length N is then sorted in O(N) time.

(?)

Sorts all elements in a single run.

Sorts a list of the strings in one run.

Sorts a vector of strings in 3 runs.

In other words when a vector of strings is sorted in O(N) time it isn't limited to a small list of values, it can be a sequence of strings (or other vectors), arrays or any other kind of list.

For more information about sorting and other implementations, check out this excellent reference.

So where is my list of useful methods?

There are quite a few methods that you need to know about as well.

The Standard Sort

When the standard Algorithm 1 is used the following algorithms are often used.

Normal sort takes an array of characters (usually a List) and sorts each string (it's a list, it's not a variable array), in O(log N).

To avoid overloading the sort_list() method, Algorithm 2 is sometimes used by many programmers as it is faster and shorter than Algorithm 1. However, the performance and scalability of Algorithm 2 is often limited to a limited set of cases, such as data-tables. Also when working with large lists or tables it might be a very bad idea to override Algorithm 1 because it takes so much more time. If that's the case, you could try to find a replacement for Algorithm 2 such as LBR or L2 insertion sort, then pick the right Algorithm when the data becomes small enough ? more on this later. But I don't suggest you try this with the lists and databases, they probably have their own special sorting algorithm.

sort_list() is not that much slower than sort()

Thanks


April 20, 2021 at 2:07 PM

Hi,

Here is example of QuickSort in Java:

Thanks

Ads









Related Tutorials/Questions & Answers:
What is QuickSort
What is QuickSort  Hi, What is QuickSort and how it can... a good thing. So what does QuickSort do? QuickSort performs the following tasks... choose to use the built-in QuickSort implementation or another one that is much
quicksort
quicksort  public static double median (double []A) { int n = A.length; quicksort(A); //sort the elements of A using quicksort if ((n % 2) == 1)return A[n/2]; else return (A[n/2 - 1] + A[n/2])/ 2.0
Advertisements
what is bit
what is bit  what is bit
What is procedure
What is procedure  What is procedure in computers? What are the primary categories of procedures
what is hibernate.archive.autodetection
what is hibernate.archive.autodetection  what is hibernate.archive.autodetection? what is autodetection and why it is used
what is hibernate.archive.autodetection
what is hibernate.archive.autodetection  what is hibernate.archive.autodetection? what is autodetection and why it is used
what is hibernate.archive.autodetection
what is hibernate.archive.autodetection  what is hibernate.archive.autodetection? what is autodetection and why it is used
what is hibernate.archive.autodetection
what is hibernate.archive.autodetection  what is hibernate.archive.autodetection? what is autodetection and why it is used
what is hibernate.archive.autodetection
what is hibernate.archive.autodetection  what is hibernate.archive.autodetection? what is autodetection and why it is used
what is hibernate.archive.autodetection
what is hibernate.archive.autodetection  what is hibernate.archive.autodetection? what is autodetection and why it is used
what is collections?
what is collections?  what is collections
what are indices?
what are indices?  what are indices
What is Hibernate
What is Hibernate  Hi, What is Hibernate? Thanks
What is Hibernate
What is Hibernate  Hi, What is Hibernate? Thanks
What is Hibernate
What is Hibernate  Hi, What is Hibernate? Thanks
What is Hibernate
What is Hibernate  Hi, What is Hibernate? Thanks
What is an Abstract Class and what is it's purpose?
What is an Abstract Class and what is it's purpose?   Hi, What is an Abstract Class and what is it's purpose? Thanks
What is Externalizable?
What is Externalizable?   Hi, What is Externalizable? Thanks
What is the % operator?
What is the % operator?   Hi, What is the % operator? thanks
What is casting?
What is casting?   Hi, What is casting? thanks
What is DataAccessException?
What is DataAccessException?  Hi, What is DataAccessException? thanks
What is IOC ?
What is IOC ?  HI, What is IOC or Dependency Injection? Thanks
What is SQLExceptionTranslator?
What is SQLExceptionTranslator?  Hi, What is SQLExceptionTranslator? Thanks
What are Struts?
What are Struts?  What are Struts? Can anyone explain me what are the Struts framework and what are its uses? Thanks
What is WAP?
What is WAP?  What is WAP?   Hi, Check the tutorial: What is WAP? Thanks
What is CRM?
What is CRM?  Can anyone tell me What is CRM? Thanks
What is webservices?
What is webservices?  What is web-services and what are the different types of web-services? It would be great if someone explain me the difference between these types of web-services in Java
What is Ajax?
What is Ajax?  Hi, What is Ajax and what is use of Ajax in web programming? Thanks   Hi, Ajax stands for AJAX stands for Asynchronous... JavaScript and other technologies such as CSS and XML. Read more at What is Ajax
What is NSRangeException
What is NSRangeException  Can anyone explain the NSRangeException and the reason why it occurs
What is portal
What is portal  What is portal What is portal and how can i create a portal in Java using components like Java and Java servlet? What are the elements of a portal and how can i create sigle request portal page in Java
What was ENIAC
What was ENIAC  What was ENIAC?   ENIAC was first electronic computer. Full form of ENIAC is Electronic Numerical Integrator And Computer

Ads