[algogeeks] Re: Test Cases

2011-07-02 Thread Ritesh Srivastava
Asymptotic complexity can never be better than O(n). But you can reduce the number of exact comparisons from 2n to 3n/2 . Take pair of numbers in each iteration and compare them. Then compare the smaller to Min and greater to Max . This way, you have 3 comparisons for every iteration where the

[algogeeks] Re: Test Cases

2011-07-01 Thread Hemanth 007
Hii, One improvement is that finding min and max can be done in a single run, rather than calling the findMin and findMax separately. But yet the order is O(n); Is there any better soln than O(n); #includestdio.h #includelimits.h void findExtreme(int array[],int size,int* min,int* max){

[algogeeks] Re: Test Cases

2011-07-01 Thread rajeevrvis
Are there any Algorithms for finding efficient max differences ? On Jul 1, 11:42 pm, Hemanth 007 hemanth2...@gmail.com wrote: Hii, One improvement is that finding min and max can be done in a single run, rather than calling the  findMin and findMax separately. But yet the order is O(n); Is

Re: [algogeeks] Re: Test Cases

2011-07-01 Thread Hemanth Sagar
The most efficient code will be surely of O(n). This is because there is no way of finding the min and max without scanning the entire array atleast once. Is this so? or any counter arguments ? On Sat, Jul 2, 2011 at 1:06 AM, rajeevrvis rajeev.open.1...@gmail.comwrote: Are there any Algorithms

Re: [algogeeks] Re: Test Cases

2011-07-01 Thread sameer.mut...@gmail.com
@hemanth: doing it in seperate for loops or in a single for loop both results in O(n) time.It does not make a difference. I think there cannot be a solution better than O(n) as we need to traverse the array atleast once. On Fri, Jul 1, 2011 at 12:57 PM, Hemanth Sagar

Re: [algogeeks] Re: Test Cases

2011-07-01 Thread Hemanth Sagar
@sameer Though the asymptotic time complexity is equal,i.e. O(n), the actual time complexity is also influenced by the constants. I claim that running two loops will be slower because there are now three operations that are to be done additionally than the single loop. Also, if you take the case

[algogeeks] Re: Test Cases

2011-05-10 Thread Don
I would add that you should test all combinations of positive and negative operands. You are not clear about the type being divided. If it is a floating point type, you can verify that (a*b) / b = a to an acceptable tolerance for a wide variety of values of a and b. If you are working with