[algogeeks] Re: Google Interview Question

2010-12-28 Thread suhash
Btw...another observation in case 1.2: I wrote: Now, let v=min(x[1],x[2],x[3],.x[k]), and 'h' be the index of the minimum element(x[h] is minimum) Then, dp[i][j]=v+sigma(f!=h)[min(x[f],y[f])] Here, just setting dp[i][j]=v will do (athough the complexity is same in both the cases) because for

[algogeeks] Re: arrays

2010-12-28 Thread juver++
Sort first array preserving the initial position of the elements. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] 10 Most Frequent Search Text

2010-12-28 Thread juver++
We don't know how many elements in the stream. All decisions should be done at online. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email

[algogeeks] Re: Find all the subset of an array whose sum is equal to some number

2010-12-28 Thread shanushaan
Well All the subsets, not the number On Dec 25, 8:48 pm, juver++ avpostni...@gmail.com wrote: What you need to get for the answer - amount of such subsets or display them? First problem can be solved using DP. Second - brute force. -- You received this message because you are subscribed to

[algogeeks] Re: Interview question amazon

2010-12-28 Thread master007
There are 3 paths exist in bst, post, pre and inorder. store all these paths and find contiguous sum(and set of elements which leads to this sum) and check if it equals to given sum, then that is path. On Dec 27, 6:48 pm, mohit ranjan shoonya.mo...@gmail.com wrote: any hint for below question

[algogeeks] Re: DIVIDE TWO VARYING LENGTH NUMBERS.

2010-12-28 Thread shanushaan
The better option will be to shift and divide. As you can store the arbitrary large number in a link list or int array. Left shift the right array and subtract, this will give you a better approach, rathar than just subtracting each time. Add them in the end .. On Dec 27, 1:47 am, Aniket

Re: [algogeeks] Google Interview Question

2010-12-28 Thread Terence
@ pacific: Also consider the choice of flipping the node itself. And if an internal node cannot be flipped, it is still possible to flip its value, only the above choice is not taken into consideration.. On 2010-12-28 13:27, pacific pacific wrote: here is my approach : Starting from the root

[algogeeks] Re: Find all the subset of an array whose sum is equal to some number

2010-12-28 Thread shanushaan
Thanks , I need to learn sml now :). I was looking for the conversation over algo development and hints to do that. On Dec 25, 10:04 pm, Puneet Ginoria punnu.gino...@gmail.com wrote: This attachment contains the code for the above program in SML language and it uses lambda calculus. On

[algogeeks] Re: Find all the subset of an array whose sum is equal to some number

2010-12-28 Thread shanushaan
On what basis we will divide the array. (Eg 1. Sort and divide them on positive negative ) On Dec 25, 10:52 pm, radha krishnan radhakrishnance...@gmail.com wrote: This s similar to the problemhttps://www.spoj.pl/problems/SUBSUMS/ we have to split the array into 2 arrays say A,B generate all

Re: [algogeeks] Re: Google Interview Question

2010-12-28 Thread Terence
The description on internal nodes indicates this: The value of an AND gate node is given by the logical AND of its TWO children's values. The value of an OR gate likewise is given by the logical OR of its TWO children's values. On 2010-12-28 13:35, suhash wrote: Your approach is for a

Re: [algogeeks] Re: Google Interview Question

2010-12-28 Thread Terence
Let cst[i][j] store the cost to flip node i to given gate j (0-'AND', 1-'OR'). Then: cst[i][j] = 0,if j==gate[i]; cst[i][j] = 1,if j!=gate[i] and ok[i]; cst[i][j] = INFINITY, if j!=gate[i] and !ok[i]; 1. To get value 1: 1.1 flip current gate to AND, and change all

Re: [algogeeks] Re: arrays

2010-12-28 Thread Bhoopendra Singh
Is second array sorted? On Tue, Dec 28, 2010 at 1:57 PM, juver++ avpostni...@gmail.com wrote: Sort first array preserving the initial position of the elements. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] Re: Interview question amazon

2010-12-28 Thread juver++
Incorrect. Path can be combined from the several traversal algorithm's output. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Google Interview Question

2010-12-28 Thread suhash
@Terence: I like your explanation. Very short and crisp! :) On Dec 28, 12:10 pm, Terence technic@gmail.com wrote: Let cst[i][j] store the cost to flip node i to given gate j (0-'AND', 1-'OR'). Then: cst[i][j] = 0,        if j==gate[i];        cst[i][j] = 1,        if j!=gate[i] and ok[i];

[algogeeks] Re: Google Interview Question

2010-12-28 Thread suhash
Sorry my mistake! But the general problem with more than 2 children possible is more interesting! :) On Dec 28, 10:58 am, Terence technic@gmail.com wrote: The description on internal nodes indicates this: The value of an AND gate node is given by the logical AND of its TWO children's

[algogeeks] Re: Interview question amazon

2010-12-28 Thread shanushaan
Not clear what path you are referring to. Question. Should the path include root value always? (What is problem with only left or only right path (not containing root)) In your example for 16 one more path can be 0 1 5 10 as well. Should algo return all the paths or just first one.

Re: [algogeeks] Re: arrays

2010-12-28 Thread Wladimir Tavares
Consider your example: One is 2 5 1 6 4 3 other is 1 2 3 4 5 6. After sorted the first array and keep the position you will have: (1,3) (2,1) (3,6) (4,5) (5,2) (6,3) O(n log n) for each value of the second array do a binary search in the first array and discover the position O (log n)

Re: [algogeeks] Re: arrays

2010-12-28 Thread Anand
@ Wladimir How do you get (1,3) (2,1) (3,6) (4,5) (5,2) (6,3) B'cos once you sort the array you lose its original index. On Tue, Dec 28, 2010 at 5:50 AM, Wladimir Tavares wladimir...@gmail.comwrote: Consider your example: One is 2 5 1 6 4 3 other is 1 2 3 4 5 6. After sorted the

Re: [algogeeks] Re: arrays

2010-12-28 Thread Anand
Now the question boils down to how to sorted the array preserving its index. On Tue, Dec 28, 2010 at 12:27 AM, juver++ avpostni...@gmail.com wrote: Sort first array preserving the initial position of the elements. -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: Interview question amazon

2010-12-28 Thread yq Zhang
I think the original question says Path can go from left subtree tree , include root and go to right tree as well. This should mean the path must include the root. On Tue, Dec 28, 2010 at 4:52 AM, shanushaan er.srivastavaro...@gmail.comwrote: Not clear what path you are referring to.

[algogeeks] Re: Interview question amazon

2010-12-28 Thread suhash
And of course boundary cases(leaf nodes) are to be handled. For a leaf node 'i', ok[i][j]=1(if j==v[i]), 0 otherwise!!! On Dec 28, 11:04 pm, suhash suhash.venkat...@gmail.com wrote: I think this can be solved using dp. Consider the subtree rooted at node 'i'. Let ok[i][j] be a boolean (0 or 1)

Re: [algogeeks] Re: arrays

2010-12-28 Thread Wladimir Tavares
Hi Anad, You can create a struct with this information typedef struct TArray{ int value; int index; }; TArray a[100]; Wladimir Araujo Tavares http://www.si.ufc.br/~wladimir http://www.si.ufc.br/%7Ewladimir/ Fiz uma faculdade! Só não fiz a segunda porque acabaram os tijolos. On Tue, Dec

Re: [algogeeks] Re: arrays

2010-12-28 Thread Anand
if I already have a structure indicating the position of the element in the array. Then why do we need to sort. Question is to provide index of element in O(nlogn). On Tue, Dec 28, 2010 at 2:20 PM, Wladimir Tavares wladimir...@gmail.comwrote: Hi Anad, You can create a struct with this

Re: [algogeeks] Re: arrays

2010-12-28 Thread jai gupta
for each element in the second array apply binary search in first array. ie, For X[1] find 1 in first array with binary search. Time Complexity=O(nlogn) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: arrays

2010-12-28 Thread Abioy Sun
Hello, 2010/12/29 Anand anandut2...@gmail.com: if I already have a structure indicating the position of the element in the array. Then why do we need to sort. Question is to provide index of element in O(nlogn). You do not have a structure before preprocessing the data, whose complexity is