Grouping sets algorithm -
need develop algorithm solve following task
given:
the n sets different number of elements expected result:
the new m sets containing ≥x common elements of n sets example:
n1=[1,2,3,4,5] n2=[2,3,5] n3=[1,3,5] n4=[1,2] if x=3: m1=[1] (from n1,3,4) m2=[2] (from n1,2,4) m3=[3,5] (from n1,2,3)
given n sets (noted ni) of sorted integers, initialize n variableshiwhich hold heads of each set.
while there still exist indexeshithat haven't reached end of respectiveni, iterate on valuesvi=ni[hi]and find minimum valuevmin, count number of occurrencesnand store corresponding indexesj(which can in 1 loop).
increment thehj.
ifn>x, gives new setm = [vmin] (from nj).
up model data representation accordingly use(from nj)as map key.
Comments
Post a Comment