Finding out the minimum difference between elements in an array

前端 未结 8 641
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 01:02

I have an integer array with some finite number of values. My job is to find the minimum difference between any two elements in the array.

Consider that the array co

8条回答
  •  执念已碎
    2020-12-08 01:29

    This is actually a restatement of the closest-pair problem in one-dimension. https://en.wikipedia.org/wiki/Closest_pair_of_points_problem http://www.cs.umd.edu/~samir/grant/cp.pdf

    As the Wikipedia article cited below points out, the best decision-tree model of this problem also runs in Ω(nlogn) time.

提交回复
热议问题