I have n sorted lists (5 <n <300). These lists are quite long (300,000+ tuples). The choice of the top k individual lists is, of course, trivial - they are at the head of the lists.
Example for k = 2:
top2 (L1: [ 'a': 10, 'b': 4, 'c':3 ]) = ['a':10 'b':4]
top2 (L2: [ 'c': 5, 'b': 2, 'a':0 ]) = ['c':5 'b':2]
Where it gets interesting when I want to combine the top k across all sorted lists .
top2(L1+L2) = ['a':10, 'c':8]
Just combining the top k of a single list will not necessarily give the correct results:
top2(top2(L1)+top2(L2)) = ['a':10, 'b':6]
The goal is to reduce the required space and keep the sorted lists small.
top2(topX(L1)+topX(L2)) = ['a':10, 'c':8]
, k, , . : X, ?
. . .
top2(magic([L1,L2])) = ['a', 'c']