DSAVisualiseData Structures & Algorithms Studio
Sorting & Selection Hard

Column Aggregation Sort

Aggregate stably sorts rows by one chosen column, then combines each contiguous key group into a row of per-column modes.

Trace input

Bounded JSON

Edit the lesson input, then build a deterministic source-linked trace.

This lesson validates its own input and operation limits.

Source scenarios

Complexity

BestO(N log N + N·M)
AverageO(N log N + N·M)
WorstO(N log N + N·M) expected with HashMap
SpaceO(N·M)

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Follow the selected-column sort, detect each group boundary, count each column's values with a frequency map, and append the resulting mode row. Tied modes use the smallest integer.

  • The grouping key is selected by column index; the output keeps the original column order.
  • Each group output cell is a mode, not the first row's value or a sum.
  • A frequency tie chooses the smaller integer, including when values are negative.
  • Groups appear in ascending order of the selected column.
  • Arrays.sort on the Java object array is stable, so rows with equal keys retain their input order while they are scanned.
  • The upstream method sorts the supplied input array in place; this deterministic trace keeps a private working copy so replay does not mutate caller input.
  • The upstream implementation reads input[0], so this lesson requires a nonempty, rectangular matrix and a valid column.

Algorithm code

Java
Aggregate.javaStep linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1