page_title: Comparison sort
hierarchical_section_title: Comparison sort
caption_attribution_description: Balance à tabac
context_page_description: A comparison sort is a type of sorting algorithm that only reads the list elements through a single abstract comparison operation that determines which of two elements should occur first in the final sorted list. The only requirement is that the operator forms a total preorder over the data, with:
  if a ≤ b and b ≤ c then a ≤ c
  for all a and b, a ≤ b or b ≤ a.
  It is possible that both a ≤ b and b ≤ a; in this case either may come first in the sorted list. In a stable sort, the input order determines the sorted order in this case.
  A metaphor for thinking about comparison sorts is that someone has a set of unlabelled weights and a balance scale. Their goal is to line up the weights in order by their weight without any information except that obtained by placing two weights on the scale and seeing which one is heavier.
context_section_description: A comparison sort is a type of sorting algorithm that only reads the list elements through a single abstract comparison operation (often a "less than or equal to" operator or a three-way comparison) that determines which of two elements should occur first in the final sorted list. The only requirement is that the operator forms a total preorder over the data, with:
  if a ≤ b and b ≤ c then a ≤ c (transitivity)
  for all a and b, a ≤ b or b ≤ a (connexity).
  It is possible that both a ≤ b and b ≤ a; in this case either may come first in the sorted list. In a stable sort, the input order determines the sorted order in this case.
  A metaphor for thinking about comparison sorts is that someone has a set of unlabelled weights and a balance scale. Their goal is to line up the weights in order by their weight without any information except that obtained by placing two weights on the scale and seeing which one is heavier (or if they weigh the same).
caption: Sorting a set of unlabelled weights by weight using only a balance scale requires a comparison sort algorithm.
exif: {"Image XResolution": "180", "Image YResolution": "180", "Image ResolutionUnit": "Pixels/Inch", "Image Software": "Paint.NET v3.36", "Image ExifOffset": "106"}