find common elements in k sorted arrays

solution 1 : similar to merge sort O(nk*log(k)), space O(nk)

get common elements for each 2 sorted arrays ( 谁小移谁)first level, get common elements for each 2 sorted arrays from the previous level result, until only one array left.

solution 2: Iterative O(nk) space O(n)

get common elements two by two

common(common(A1, A2), A3,....Ak)

A1

A2

A3

...

Ak

results matching ""

    No results matching ""