Top-K cutoff explorer
See who makes the cut when scores tie. Compare exact K by input order, exact K by ID, and all records tied at the cutoff.
Selection results
6 records · K = 3 · Cutoff score 92 · 3 at that score.
- Exact K, input order for ties
- 3 selected: birch → fir → cedar
- Exact K, ascending ASCII ID for ties
- 3 selected: birch → fir → alder
- Include all ties at the cutoff
- 5 selected: birch → fir → cedar → ash → alder (+2 beyond exact K)
| ID | Score | Input position | Exact K: input | Exact K: ID | All cutoff ties |
|---|---|---|---|---|---|
| cedar | 92 · cutoff | 1 | 3 | — | 3 |
| birch | 95 | 2 | 1 | 1 | 1 |
| ash | 92 · cutoff | 3 | — | — | 4 |
| elm | 85 | 4 | — | — | — |
| fir | 95 | 5 | 2 | 2 | 2 |
| alder | 92 · cutoff | 6 | — | 3 | 5 |
Select and copy the report to keep the normalized scores, input positions, and each returned order.
What changes when three scores tie at the cutoff?
In the default example, birch and fir score 95. Cedar, ash and alder score 92. For K = 3, input order gives the last slot to cedar. Ascending ASCII ID gives it to alder. Keeping everyone at the cutoff returns five records, with equal scores in input order. The comparison table shows exactly which rows move or drop out.
Choose the tie policy before comparing results
Use input order when it represents a meaningful arrival sequence. Use stable IDs when the same records should win after the input is reshuffled. Use an inclusive cutoff when excluding any equally scored record would violate the reporting rule. That policy can exceed K by more than one, so check the output budget.
Read the result when K does not name a row
At K = 0 all policies return nothing. If K exceeds the number of records, all available records are returned, in each policy’s declared order, and there is no Kth score. An empty input produces no winners. When K equals the input length, the last score is the cutoff and no additional rows can be included.
How scores and IDs are compared
Scores are stored as integer thousandths, so spellings such as 1.2 and 1.200 compare equally. Negative zero displays as zero. The ID policy uses case-sensitive ASCII order, which places uppercase A before lowercase a. This is an exact comparison for the accepted format, not a locale-aware sort or a floating-point tolerance.
Take the same policy into your code
This small tool sorts its bounded input to show all comparison rows. It does not benchmark heap selection or process a live stream. The Python top-K guide includes tested selection examples and a bounded heap. For full-array order and mutation, use the sorting explorer.
References: Python heapq selection and stable sorting and secondary keys.