find if two arrays contain the same set of integers without extra space and faster than NlogN

前端 未结 14 775
盖世英雄少女心
盖世英雄少女心 2020-12-02 17:27

I came across this post, which reports the following interview question:

Given two arrays of numbers, find if each of the two arrays have the same s

14条回答
  •  遥遥无期
    2020-12-02 17:56

    In the algebraic decision tree model, there are known Omega(NlogN) lower bounds for computing set intersection (irrespective of the space limits).

    For instance, see here: http://compgeom.cs.uiuc.edu/~jeffe/teaching/497/06-algebraic-tree.pdf

    So unless you do clever bit manipulations/hashing type approaches, you cannot do better than NlogN.

    For instance, if you used only comparisons, you cannot do better than NlogN.

提交回复
热议问题