[algogeeks] maximum difference in an array

2011-03-30 Thread UTKARSH SRIVASTAV
Problem
Can anyone give me the efficient algo to know the the maximum difference of
two numbers in an arrayplease 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.



Re: [algogeeks] maximum difference in an array

2011-03-30 Thread Subhransu
Don't you think sorting the array and take the first  last element ! ! !

*Subhransu Panigrahi
*
*Mobile:* *+91-9840931538*
 *Email:* subhransu.panigr...@gmail.com



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 arrayplease 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.



Re: [algogeeks] maximum difference in an array

2011-03-30 Thread Senthil S
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 arrayplease 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.