Re: [algogeeks] Amazon written test question

2012-02-23 Thread HARISH S.C
Hi, Construct a BST with 2,1,3. If my understanding is right, now distance between 2,3 will be 2. Will this algo return the correct answer?. On Thu, Feb 2, 2012 at 1:43 PM, Manni mbd mbd2...@gmail.com wrote: Forget my previous post. it useless i think Firstly there will be only 1 node

[algogeeks] Maximize XOR

2012-02-23 Thread sunny agrawal
Given an array of N integers, Find two Numbers with max XOR value. Naive Algorithm is O(N^2), what can be a better approach ? -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Maximize XOR

2012-02-23 Thread Dipit Grover
http://discuss.joelonsoftware.com/default.asp?interview.11.614716 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
Why are you using tail recursion when an iterative approach would be more efficient? Don On Feb 23, 3:41 am, rahul sharma rahul23111...@gmail.com wrote: struct node* SortedMerge(struct node* a, struct node* b) {   struct node* result = NULL;   /* Base cases */   if (a == NULL)      

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
// Iterative merge struct node* SortedMerge(struct node* a, struct node* b) { struct node* head, tail; // Select first node if (a-data b-data) { head = tail = a; a = a-next; } else { head = tail = b; b = b-next; } // Merge lists while(a b) { if (a-data

Re: [algogeeks] merge two sorted list

2012-02-23 Thread atul anand
output is 10 10 20 25 30 On Thu, Feb 23, 2012 at 4:44 PM, Karthikeyan V.B kartmu...@gmail.comwrote: Hi, this logic generates 10 10 20 25 .. and so on it doesn delete the duplicates in the result list -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
Is the desired behavior to remove duplicates? On Feb 23, 5:14 am, Karthikeyan V.B kartmu...@gmail.com wrote: Hi, this logic generates 10 10 20 25 .. and so on it doesn delete the duplicates in the result list -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: merge two sorted list

2012-02-23 Thread Ashish Goel
tails needs to be updated in while loop also Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, Feb 23, 2012 at 8:19 PM, Don dondod...@gmail.com wrote: // Iterative merge struct node* SortedMerge(struct node* a, struct node* b) { struct

[algogeeks] Re: Longest Path in A Graph

2012-02-23 Thread Krishna Kishore
Thank You very much friends. I ve read algorithm Topological Sorting. First we have to perform the topological sorting ( in Linear Time ) on the graph. Then we can find which is the Longest Path in that ordering. But it works for only DAG ( Directed Acyclic Graphs ). I ve done it. But after