Sorting algorithms

From Citizendium - Reading time: 2 min

This article is a stub and thus not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

Sorting algorithms are processes to follow for sorting lists of data. They are commonly used as an introduction to algorithms for students of computer science.

There are many different strategies that can be used to sort data. These include sorting by insertion, by exchanging, by selection, by merging, and by distribution.[1]

Sorting by Insertion[edit]

Sorting by insertion works by inserting elements back into the place where they belong in an already sorted sequence until all elements are inserted and the sequence is sorted.

The classic example of a sort by insertion is insertion sort. For the kth iteration of insertion sort, are already sorted and is inserted into the location in this sorted subsequence.

A more efficient sort that uses insertion is Shellsort.

Sorting by Exchanging[edit]

Sorting by exchanging works by exchanging elements that are not in the right order until the sequence is sorted.

The classic example of a sort by exchanging is bubble sort. Bubble sort works by repeatedly passing over the sequence and exchanging adjacent elements that are out of order until the whole array is in order.

A more efficient sort that uses exchanges is Quicksort.

Sorting by Selection[edit]

Sorting by selection works by selecting the element that belongs in the correct places in the sequence until all elements of the sequence are selected for their correct positions and the sequence is sorted.

The classic example of a sort by selection is selection sort. Selection sort works by finding the smallest of the unsorted portion of the sequence and placing it at the end of the sorted point of the sequence until the array is completely sorted.

A more efficient sort that uses selection is Heapsort.

Sorting by Merging[edit]

Sorting by merging works by sorting smaller subsequences then merging them together into larger sorted sequences.

The classic example of a sort by merging is merge sort. Merge sort works by dividing the seqeunce into halves repeatedly until the subsequences are trivially sorted then merging the sorted subsequences together until the whole sequence is sorted.

Sorting by Distribution[edit]

Sorting by distribution works by placing the elements into categories then putting the elements in the categories back into the sequence in sorted order. This can be faster than the other methods, but it can require a lot more memory.

The classic example of a sort by distribution is radix sort. Radix sort works by taking placing fixed-width numbers into categories based off their last digit. It then collects back the categories in order of the last digit and repeats the process for the second to last digit, and continues for each digit until the first one.

References[edit]

  1. Donald Knuth, The Art of Computer Programming Addison-Wesley, 1973, ISBN 0-201-03803-X.

Licensed under CC BY-SA 3.0 | Source: https://citizendium.org/wiki/Sorting_algorithms
26 views | Status: cached on November 15 2024 14:28:38
↧ Download this article as ZWI file
Encyclosphere.org EncycloReader is supported by the EncyclosphereKSF