Re: [algogeeks] Build BST from binary tree without extra space

2010-04-28 Thread Vivek S
@Rajesh Patidar I think we should do in Post order traversal alone. If we go by Preorder/Inorder we might lose track of children node that is currently being inserted into the BST. - correct me if im wrong :) On 28 April 2010 15:30, Rajesh Patidar patidarc...@gmail.com wrote: pickup node in

Re: [algogeeks] MXN matrix

2010-04-28 Thread Vivek S
Let Memo[i][j] be the sum of elements in the (sub) rectangle from (0,0) to (i,j) Then use principle of inclusion and exclusion to find the sum of elements from (a, b) to (c, d) in O(1) for N*N matrix, Complexity is O(N^4) On 28 April 2010 13:36, Ashish Mishra amishra@gmail.com wrote: you

Re: [algogeeks] Dijkstra For Longest Path?

2010-01-14 Thread Vivek S
@chitta koushik No, That might lead to negative edge cycles! 2010/1/15 chitta koushik koushik.infin...@gmail.com How abt negating values and using same single source shortest path algo ? 2010/1/15 saltycookie saltycoo...@gmail.com longest path is NP-hard 2010/1/11 Johan

[algogeeks] Re: Good problem

2009-10-21 Thread Vivek S
to maximize the minimum distance between any two points:- to maximize the minimum distance between adjacent points - for this all points must be equally spaced. hence, choose 'n' equally spaced points in the range (r1, r2) starting from r1 and ending at r2. 2009/10/21 saltycookie

[algogeeks] Re: 100!

2009-10-10 Thread Vivek S
hope you mean find *sum* of all the digits in number-100! :) 2009/10/11 vicky mehta...@gmail.com find some of all the digits in number-100! -- Reduce, Reuse and Recycle Regards, Vivek.S --~--~-~--~~~---~--~~ You received this message because you are

[algogeeks] Re: minimum difference.

2009-09-02 Thread Vivek S
@Varun S VIt wont work for this 1 3 4 5 2009/9/2 Varun S V varun...@gmail.com Since we difference between two minumum elements should suffice, how about finding the min and second minimum element in the array in single scan and returning their difference. This should take not more than O(N)

[algogeeks] Re: Find longest interval

2009-08-26 Thread Vivek S
let A[i+1] = a[0] + a[1] + ... + a[i]; let B[i+1] = b[0] + b[1] + ... + b[i]; A[0] = B[0] = 0; sum of nos from i to j of a[] = A[j+1] - A[i]; // O(1) time Thus O(n^2) sol can be obtained for this problem by finding the sub-array sum in the range [i, j] for every i, j; But I have not used the fact

[algogeeks] Re: Missing numbers

2009-07-31 Thread Vivek S
@Devi; Consider this, N = 2 The array elements should these (N+2), numbers : {1, 2, 3, 4} If the given array is {4, 3} Will your code work correctly? 2009/7/31 Devi G devs...@gmail.com The logic is actually simple. Tot if we mark in some way an element when it's scanned, we can find the

[algogeeks] Re: Missing numbers

2009-07-31 Thread Vivek S
N! overflows... Try to write a program to find the value of 30! You don't have a variable that is large enough to store such a big number... 2009/7/31 sharad kumar aryansmit3...@gmail.com check this out Let x and y be the missing number, Now equation 1 is : x + y = [n(n+1)/2] - S equation