The question I'm faced with:

Let $A[1], A[2], ...,A[n]$ be an array containing $n$ very large positive integers.

Describe an efficient algorithm to find the minimum positive difference between any two integers in the array.

What is the complexity of your algorithm? Explain.

I would assume you apply a Merge Sort or Quick Sort $\Theta(n(log (n))$ and then scan through the array, subtracting the second element from the previous element, all the way to the end? Or $n-1$ comparisons?

So the complexity would be $\Theta(n(log(n) + (n-1))$?

  • 1
    $\begingroup$ This depends on what you mean by very large integers. Could you be more specific? $\endgroup$ Oct 15, 2015 at 15:50
  • $\begingroup$ Hi! We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. $\endgroup$
    – D.W.
    Oct 15, 2015 at 17:08
  • $\begingroup$ For more detailed information on analyzing the running time of your algorithm, see our reference question: cs.stackexchange.com/q/23593/755 $\endgroup$
    – D.W.
    Oct 15, 2015 at 17:08
  • $\begingroup$ @D.W. I think the specific conceptual question is in the question -- sorting and searching an array efficiently, in this case for a specific kind of relationship between any two elements. I think far less useful to the community would simply be positing the question without any kind of attempt to think through it. Nor is it clear that questions with an academic origin have no benefit or value to the community at large -- if I solve for a Python app I'm building is it any more useful? I'm not as familiar with the charter of the community but it sounds like you're discussing preferences. $\endgroup$ Oct 15, 2015 at 18:36
  • $\begingroup$ @DennisKraft It doesn't say but I think the purpose of the "very large" limitation is to prevent the use of the radix sort algorithm. $\endgroup$ Oct 15, 2015 at 18:37


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.