What is the fastest algorithm for intersection of two sorted lists? -
say there 2 sorted lists: , b.
the number of entries in , b can vary. (they can small/huge. can similar each other/significantly different).
what known fastest algorithm functionality?
can 1 give me idea or reference?
assume a
has m
elements , b
has n
elements, m ≥ n
. information theoretically, best can is
(m + n)! lg -------- = n lg (m/n) + o(n) m! n!
comparisons, since in order verify empty intersection, have perform sorted merge. can within constant factor of bound iterating through b
, keeping "cursor" in a
indicating position @ recent element of b
should inserted maintain sorted order. use exponential search advance cursor, total cost on order of
lg x_1 + lg x_2 + ... + lg x_n,
where x_1 + x_2 + ... + x_n = m + n
integer partition of m
. sum o(n lg (m/n))
concavity of lg
.
Comments
Post a Comment