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){
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
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
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
the lists are infinitely long and you want the first 'x'
elements of the sorted list fast.
Thanks,
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
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