Sorting takes O (N logN) .. You can find the minimum and the maximum in a
single traversal i.e O(N) time and return the difference of the two ..
To find minimum and maximum you can do the following :
i) Assign min = max = first element in the array.
ii)Then traverse the array .. for each element in the array .. if it is
greater than max , update max = that element .. else if it is lesser than
min, update min as that element ..

After finding min and max return the difference of the two


On Wed, Mar 30, 2011 at 12:43 PM, UTKARSH SRIVASTAV <usrivastav...@gmail.com
> wrote:

> Problem
> Can anyone give me the efficient algo to know the the maximum difference of
> two numbers in an array............please only tell the algo not code
> -
> *UTKARSH SRIVATAV*
> *CSE-3
> B-Tech 2nd Year
> @MNNIT ALLAHABAD*
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to