Sorting Algorithms: Difference between revisions
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
The '''sorting problem''' if formally defined as follows: given a sequence of n numbers (a<sub>1</sub>, a<sub>2</sub>, ... a<sub>n</sub>) provided as input, the algorithm must produce as output a permutation (reordering) (a<sup>'</sup><sub>1</sub>, a<sup>'</sup><sub>2</sub>, ... a<sup>'</sup><sub>n</sub>) of the input sequence such that a<sup>'</sup><sub>1</sub> ≤ a<sup>'</sup><sub>2</sub> ≤ ... ≤ a<sup>'</sup><sub>n</sub>. A specific input sequence is called an '''[[Data Structures and Algorithms#Instance_of_the_problem|instance]]''' of the sorting problem. | The '''sorting problem''' if formally defined as follows: given a sequence of n numbers (a<sub>1</sub>, a<sub>2</sub>, ... a<sub>n</sub>) provided as input, the algorithm must produce as output a permutation (reordering) (a<sup>'</sup><sub>1</sub>, a<sup>'</sup><sub>2</sub>, ... a<sup>'</sup><sub>n</sub>) of the input sequence such that a<sup>'</sup><sub>1</sub> ≤ a<sup>'</sup><sub>2</sub> ≤ ... ≤ a<sup>'</sup><sub>n</sub>. A specific input sequence is called an '''[[Data Structures and Algorithms#Instance_of_the_problem|instance]]''' of the sorting problem. | ||
The numbers we wish to sort are also known as '''keys'''. | |||
<span id='Comparison_Sort'></span>'''Comparison sort'''. Cannot do better than n lg n. Proof in a separate article. | <span id='Comparison_Sort'></span>'''Comparison sort'''. Cannot do better than n lg n. Proof in a separate article. |
Revision as of 04:17, 5 August 2018
Internal
Overview
Many programs use sorting as an intermediate step, and that is why sorting is considered a fundamental operation in computer science.
The sorting problem if formally defined as follows: given a sequence of n numbers (a1, a2, ... an) provided as input, the algorithm must produce as output a permutation (reordering) (a'1, a'2, ... a'n) of the input sequence such that a'1 ≤ a'2 ≤ ... ≤ a'n. A specific input sequence is called an instance of the sorting problem.
The numbers we wish to sort are also known as keys.
Comparison sort. Cannot do better than n lg n. Proof in a separate article.
Non-comparison sort.
Sorting algorithms characteristics:
- in-place
- stability