[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){

Re: [algogeeks] Re: Test Cases

2011-07-01 Thread Hemanth Sagar
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 there any better

Re: [algogeeks] Re: Test Cases

2011-07-01 Thread Hemanth Sagar
of insertion sort (vs) merge sort, though the time complexity of merge sort (nlogn) is better than insertion sort(n^2), for small n values, insertion sort is better. This is because there is also a role played by the constants. Correct me if I am wrong ! - Hemanth On Sat, Jul 2, 2011 at 8:20 AM

[algogeeks] Re: Given an array containing both positive and negative integers, we r required to find the sub-array with the largest sum

2006-01-25 Thread Hemanth
cumulative sum point. Then we can ignore numbers from 0 to x (inlcuding x) since they do not contribute to the cumulative sum. So, the indices of the sub-array with the maximal sum should be (x+1, y) Thanks, Hemanth

[algogeeks] Re: Typical Interesting questions

2006-01-18 Thread Hemanth
the lists are infinitely long and you want the first 'x' elements of the sorted list fast. Thanks, Hemanth

[algogeeks] Re: Given N numbers z value , find x, y such that x + y = z

2005-12-20 Thread Hemanth
Hi, Let me try to slightly present the problem in a different way. 1. First go through the unsorted array and get two smaller arrays. One array containing numbers = z/2 and other array containing numbers z/2 and = z. Other numbers obviously can be ignored. 2. Now 'z' complement(i.e. number

[algogeeks] Re: Given N numbers z value , find x, y such that x + y = z

2005-12-19 Thread Hemanth
This answer is something like a bit vector based one. Assume that the array is int[] num. for(int i = 0; i num.length; i++) { int otherNum = z - num[i]; // Search in a hashmap we maintain for 'otherNum' // if 'otherNum' is present, then we are done // else add 'num[i]' to the