A little room to wonder

Data Tables & Sorting

Keep related values together while ordering records, and define what happens when sorting keys tie.

Why can sorting one column by itself damage a table?

An IBM punched-card sorter has a row of output compartments for sorted cards.
The approved punched-card sorter makes physical record organisation visible. It does not establish the fictional table’s keys or the machine’s complete sorting algorithm.waelder · Source · CC BY 2.5

A row is a related record

A simple table can store one record per row and one attribute per column. In an invented reading list, a row might contain a card ID, title and page count. The heading tells you what a value represents; a number without its heading can be ambiguous.

If you sort only the page-count column while leaving titles in place, the values no longer describe the original records. Ordering should move whole rows together unless the task explicitly creates a new, separate summary. Neat columns are not evidence that relationships have been preserved.

Choose a key and direction

A sorting key is the attribute used for comparison. Ascending page count differs from alphabetical title order. Numeric comparison also differs from text comparison: the numeral strings 10 and 2 may be ordered differently from the numbers 10 and 2, depending on the chosen rule.

A secondary key resolves a tie in the first key. Another option is a stable sort, which preserves the original relative order among equal-key records. That is a property to specify or check, not something every imaginable sorting procedure automatically provides.

Worked example: keep the cards intact

Three fictional records are A: Cloud Map, 12 pages; B: Paper Robot, 8 pages; C: Leaf Sketch, 12 pages. Sorting by ascending page count puts B first. If the second key is alphabetical title, A comes before C, giving B, A, C.

If instead a stable page-count sort starts from the order C, B, A, the tied 12-page cards remain C before A, giving B, C, A. Neither result changes any card’s page count. The difference comes from the stated tie rule, not from one sort being mysteriously wrong.

Missing data need a visible rule

An empty page-count field is not necessarily zero. Decide whether unknown values go last, are excluded from a particular calculation or remain in an explicitly labelled group. Quietly replacing blanks with 0 changes the information.

Use an ID to check that all records survive and keep an original copy of the supplied fictional table for comparison. Sorting changes arrangement, not truth. A well-ordered table can still contain an inaccurate value, so validation and ordering remain separate tasks.

Only if you feel like trying

Sort three fictional records two ways

  1. Write each supplied record as one row or one drawn card.
  2. Apply page-count plus title order, then apply stable page-count order from C, B, A.
  3. Add a fourth record with an unknown page count and explain your missing-value rule.

Optional. Use paper or talk through the supplied fictional example. No purchase, personal information, account, public sharing or practical experiment is needed.