CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    5

    minimal distance between numbers in one dimentional array

    I there an O(n) algorithm for finding minimal distance between numbers in an one dimensional array? Does it matter if all the numbers are positive or negative? The array is not sorted

  2. #2
    Join Date
    Nov 2007
    Posts
    74

    Re: minimal distance between numbers in one dimentional array

    Yes, there is O(n) algo to solve it.

  3. #3
    Join Date
    Jan 2009
    Posts
    5

    Re: minimal distance between numbers in one dimentional array

    Quote Originally Posted by Thu View Post
    Yes, there is O(n) algo to solve it.
    does it work anyway or it depends if the numbers are positive or negative?
    can you describe the algo? thanks

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: minimal distance between numbers in one dimentional array

    Well, one approach would be to use Radix sort and then find the answer in a single pass over the sorted array.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured