Re: [algogeeks] help with o/p why 0 comes???

2013-03-04 Thread Anurag Sharma
Ya, its looking like the problem of 'i686-apple-darwin11-llvm-gcc-4.2'. For me as well it shows different outputs. On Mon, Mar 4, 2013 at 4:45 PM, rohit jangid rohit.nsi...@gmail.com wrote: yup , it is showing 0 0 on ideone as well . so my gcc compiler is i686-apple-darwin11-llvm-gcc-4.2.

Re: [algogeeks] MS Question:WAP to print last n lines of a log file

2013-03-04 Thread Anurag Sharma
Both questions look related to me. If the log file is being updated as well simultaneously, you should be able to use Circular queue/buffer for that. On Mon, Mar 4, 2013 at 9:10 AM, Ashish Goel ashg...@gmail.com wrote: Q1. Given a log file, pirnt last n lines. Note that the Log file is being

Re: [algogeeks]

2011-12-05 Thread Anurag Sharma
In context of C++ 1. Populate the digits of the given number in a vector V 2. call next_permutation() on V 3. print the vector [?] Thanks, Anurag Sharma +91-8712218874 On Tue, Dec 6, 2011 at 2:23 AM, sourabh sourabhd2...@gmail.com wrote: This problem is a direct implication

Re: [algogeeks] Amazon telephonic question

2011-06-28 Thread Anurag Sharma
for second problem, you can create a stack of having each element as a node having the current value as well as pointer to the next smallest value present below it. This can solve all 3 operations in constant time. Thanks, Anurag On Tue, Jun 28, 2011 at 3:00 PM, vikas mehta...@gmail.com wrote:

Re: [algogeeks] Re: sort in minimum cost

2011-04-29 Thread Anurag Sharma
This seems longest increasing subsequence problem to me.. Thanks, Anurag On Mon, Apr 25, 2011 at 9:31 PM, snehal jain learner@gmail.com wrote: few eg input 4 7 12 3 1 output 4 7 12 cost: 4 by removing 3 n 1 eg 2 6 3 5 7 12 4 o/p 3 3 5 7 12 cost 7 by decrementing 6 by 3 and

Re: [algogeeks] Ties The Rope With Minimum Cost ..Interesting For Geeks

2011-04-06 Thread Anurag Sharma
I think the greedy method of taking the current minimum sized 2 ropes and tying them will do. Consider this algo:- int getMinCost(){ priority_queue pq; insert all thread sizes to pq; int sum=0; while(!pq.empty()){ int a=pq.extractmin(); //O(logn) int b=pq.extractmin(); sum+=a+b;

Re: [algogeeks] Java Random Method

2010-06-26 Thread Anurag Sharma
int getNum(){ int arr[]={104,105,106,108}; return arr[(int)(Math.random()*4)]; } Anurag Sharma On Sat, Jun 26, 2010 at 8:43 PM, trdant trd...@gmail.com wrote: I have the following sequence of integers: 104,105,106,108 and need to write a Java statement to randomly produce one

Re: [algogeeks] FIND DUPLICATE IN BINARY TREE

2010-06-25 Thread Anurag Sharma
PS: read 'hashmap' in my previous post as 'hashtable' Anurag Sharma On Fri, Jun 25, 2010 at 5:55 PM, Anurag Sharma anuragvic...@gmail.comwrote: Make a Self Balancing BST like RB Tree or AVL Tree, lets call it T. ( O(n) ) Perform an inorder traversal of the Binary tree and for every element

Re: [algogeeks] FIND DUPLICATE IN BINARY TREE

2010-06-25 Thread Anurag Sharma
a hashmap instead of RB-Tree Total Time: O(n) Total Space: O(1) Anurag Sharma On Fri, Jun 25, 2010 at 5:34 PM, RIDER mohit...@gmail.com wrote: you are given a binary tree (not a BST) .how to find is there is any element which occurs twice and if so what is value ? -- You received this message

Re: [algogeeks] FIND DUPLICATE IN BINARY TREE

2010-06-25 Thread Anurag Sharma
@jalaj Tree may have negative values. Anurag Sharma On Fri, Jun 25, 2010 at 7:38 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: first do a traversal of the tree and find the maximum value now take an auxilarry aray a[MAX].. initialize this array to zero now traverse the tree and each

Re: [algogeeks] Array Problem

2010-06-24 Thread Anurag Sharma
Sorry, this point is already pointed out by Sharad. Anurag Sharma On Thu, Jun 24, 2010 at 4:42 PM, Anurag Sharma anuragvic...@gmail.comwrote: @jalaj Your approach will not work, what I perceived from your solution, as in question the maximum difference S is defined as:- S = a[i] - a[j

Re: [algogeeks] triplets summing to zero

2010-06-24 Thread Anurag Sharma
Its a repeated question. Kindly search the archives for detailed discussion. Anurag Sharma On Wed, Jun 23, 2010 at 10:55 PM, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: sort the array for each element a[i] find two elements that sum to -a[i] (this can be done in O(n

Re: [algogeeks] Array Problem

2010-06-24 Thread Anurag Sharma
@jalaj Your approach will not work, what I perceived from your solution, as in question the maximum difference S is defined as:- S = a[i] - a[j] where* ij *Perhaps you forgot that the 'order' of the max and min also matters :) Anurag Sharma On Mon, Jun 21, 2010 at 10:34 PM, jalaj jaiswal

Re: [algogeeks] There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-19 Thread Anurag Sharma
containing all even numbers. Hope its clear. Anurag Sharma On Sun, Jun 20, 2010 at 2:15 AM, vijay auvija...@gmail.com wrote: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers. The odd

Re: [algogeeks] binary tree

2010-06-17 Thread Anurag Sharma
Here is the link which fits your need. http://www.coders2020.com/construct-a-tree-given-its-inorder-and-preorder-traversal-strings-similarly-construct-a-tree-given-its-inorder-and-post-order Anurag Sharma On Thu, Jun 17, 2010 at 4:34 PM, divya sweetdivya@gmail.com wrote: write a code

Re: [algogeeks]Numbers search in an array

2010-06-17 Thread Anurag Sharma
Its a repeated question. I would suggest you checking the archives of this groups for its solution. Anurag Sharma On Fri, Jun 18, 2010 at 8:05 AM, Arunkumar Sreenivasan thegame.a...@gmail.com wrote: Hi, You are given a set of numbers and another number 'x'. You have to find

Re: [algogeeks] BST...doubt.......

2010-06-16 Thread Anurag Sharma
@sharad height will be log2(n) only in case of balanced BST. what if its terribly unbalanced, you may get height as 'n' as well ! :) So you will have to go till the bottom of the tree to see the depth and find the height accordingly. Anurag Sharma On Wed, Jun 16, 2010 at 9:12 AM, Anurag Sharma

Re: [algogeeks] Stack Space for Quick Sort vs Merge Sort.

2010-06-16 Thread Anurag Sharma
Thats what he is referring to :) Anurag Sharma On Tue, Jun 15, 2010 at 4:49 PM, Amit Jaspal iit2007...@iiita.ac.in wrote: But what about the Stack Space Used while doing Merge and Quick Sort? On Mon, Jun 14, 2010 at 9:30 AM, Anurag Sharma anuragvic...@gmail.comwrote: Seems correct to me

Re: [algogeeks] copy

2010-06-16 Thread Anurag Sharma
p may not always be (n-1) as perceived from the initial question. Like consider copying all the bits of x to y Anurag Sharma On Tue, Jun 15, 2010 at 7:02 PM, mohit ranjan shoonya.mo...@gmail.comwrote: @Sharad assuming p(n-1) o/p= x [ ~ { (~((~0)n)) (p-n+1) } ] | [ y [~((~0)n

Re: [algogeeks] op

2010-06-16 Thread Anurag Sharma
what is happening here and you will get output : *g* Anurag Sharma On Wed, Jun 16, 2010 at 8:56 AM, sharad kumar sharad20073...@gmail.comwrote: ya i forgot that...considering that plz explain o/p i.e #includemalloc.h char *f() {char *s=malloc(8); strcpy(s,goodbye

Re: [algogeeks] trees

2010-06-16 Thread Anurag Sharma
Do a level order traversal, like in BFS, and make the child sibling tree accordingly Anurag Sharma On Wed, Jun 16, 2010 at 11:59 PM, divya sweetdivya@gmail.com wrote: Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever

Re: [algogeeks] stack

2010-06-15 Thread Anurag Sharma
Why not just pop all elements from stack ( O(n) ) and insert it in a self balancing Binary Search Tree (like RB Tree) (O(log(n) ) and then do and inorder traversal ( O(n) )and push elements in stack again. Time = O(nlog(n) + n) Space=O(n) (for storing the tree) Anurag Sharma On Sun, Jun 13

Re: [algogeeks] unique number in an array

2010-06-15 Thread Anurag Sharma
the non repeating element. Anurag Sharma On Sun, Jun 13, 2010 at 11:44 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: give an algo to find a unique number in an array for eg a[]={1,3,4,1,4,5,6,1,5} here 3 is the unique number as it occur only once... moreover array contains only 1 unique

Re: [algogeeks] tower of hanoi variation

2010-06-15 Thread Anurag Sharma
I think there should be additional constraint added that atmost 1 disk can be placed in ground. Otherwise one can place all disks on ground and put them in order in the last peg :D Anurag Sharma On Mon, Jun 14, 2010 at 2:01 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: give the algorithm

Re: [algogeeks] Towers of hanoi

2010-06-15 Thread Anurag Sharma
Use iterative version :http://en.wikipedia.org/wiki/Tower_of_Hanoi Anurag Sharma On Mon, Jun 14, 2010 at 12:36 AM, ANUJ KUMAR kumar.anuj...@gmail.comwrote: http://www.spoj.pl/problems/HAN01/ i implemented it using stack but am getting tle someone please help -- You received this message

Re: [algogeeks] Re: bits

2010-06-15 Thread Anurag Sharma
@jalaj endian specific. Anurag Sharma On Sun, Jun 13, 2010 at 11:54 PM, Modeling Expert cs.modelingexp...@gmail.com wrote: @jalaj Yes , this is endian ness specific. On windows/x86 linux which are little endian, ch[0] would be lower 8 bits. On solaris/power pc which are big endian

Re: [algogeeks] Stack Space for Quick Sort vs Merge Sort.

2010-06-15 Thread Anurag Sharma
Seems correct to me :) Anurag Sharma On Sun, Jun 13, 2010 at 11:23 PM, amit amitjaspal...@gmail.com wrote: Can anyone tell what is Stack Space required for Quick Sort and Merge Sort.And how in each case it can be modified. Correct me if I am wrong on this. Space Complexity of Merge Sort

Re: [algogeeks] Re: unique number in an array

2010-06-15 Thread Anurag Sharma
thing :) Anurag Sharma On Mon, Jun 14, 2010 at 5:14 PM, Modeling Expert cs.modelingexp...@gmail.com wrote: use hash table , and if you find for a number , a entry already exists , mark it unwanted ! in the end , hash table entries are unique numbers . @kunzmilan : could you explain a bit

Re: [algogeeks] op

2010-06-15 Thread Anurag Sharma
did you forget to return any value from function f() ? Anurag Sharma On Mon, Jun 14, 2010 at 7:19 PM, sharad sharad20073...@gmail.com wrote: #includemalloc.h char *f() {char *s=malloc(8); strcpy(s,goodbye); } main() { *f()='A'; printf(%c,*f

Re: [algogeeks] Best method to choose a quadrant

2010-06-15 Thread Anurag Sharma
just check the signs of the i, j components of vector from the centre of screen to (x,y) pseudo code:- getQuadrant(x,y){ string Q[]={1st,4th,2nd, 3rd}; vx=(x=midx)?0:1 vy=(y=midy)?0:1 return Q[(vx1)|vy] } Anurag Sharma On Mon, Jun 14, 2010 at 5:55 PM, siddharth srivastava akssps

Re: [algogeeks] BST...doubt.......

2010-06-15 Thread Anurag Sharma
height of current node = max(height of left child, height of right child) +1 Hope now you get that? :) Anurag Sharma On Tue, Jun 15, 2010 at 5:31 PM, ajay kumar ajaykr@gmail.com wrote: Write a pseudo code 4 that..using c/c++... how can we find the depth(height) of BST

Re: [algogeeks] union- c

2010-06-13 Thread Anurag Sharma
Check the floating point representation(IEEE 754 format) in variables. There are specific number of bits in a float variable to represent exponent, mantissa etc. Anurag Sharma On Sun, Jun 13, 2010 at 1:19 PM, divya jain sweetdivya@gmail.comwrote: its an o/p questn.. conversion wen ur

Re: [algogeeks] Re: identify the recurring part for a given decimal no

2010-06-12 Thread Anurag Sharma
repeats hope its clear Anurag Sharma On Sat, Jun 12, 2010 at 4:02 PM, divya jain sweetdivya@gmail.comwrote: @anurag i dint get ur approach..which numerator n denominator u r talking about..plz explain.. thanks in advance On 11 June 2010 08:57, Anurag Sharma anuragvic...@gmail.com

Re: [algogeeks] c output

2010-06-11 Thread Anurag Sharma
printf returns number of successfully printed characters. so printf(1\n) will return 6 and printf(c\n) will return 2 due to the extra '\n' character which is also being printed I hope the output is now clear Anurag Sharma On Fri, Jun 11, 2010 at 12:26 AM, divya sweetdivya@gmail.com

Re: [algogeeks] Re: identify the recurring part for a given decimal no

2010-06-11 Thread Anurag Sharma
(remainder, quotient) of that division step in a set. and before inserting in the set check whether it already exists. If yes then the all the quotients following from that point (including the point) will be recurring. Regards, Anurag Sharma On Thu, Jun 10, 2010 at 8:25 AM, Veer Sharma thisisv

Re: [algogeeks] level order traversal

2010-06-11 Thread Anurag Sharma
If a doubly Linked List is made out of this, then there should be kept some mechanism to keep the parent pointer in it and update it while creating and then we can proceed in similar approach as my array solution above. Anurag Sharma On Thu, Jun 10, 2010 at 7:09 PM, sharad kumar sharad20073

Re: [algogeeks] Common elements in 2 circular linked lists

2010-06-11 Thread Anurag Sharma
Ya that will do.. Anurag Sharma On Fri, Jun 11, 2010 at 7:08 PM, Raj N rajn...@gmail.com wrote: Given a circular linked list, what is the most efficient way of constructing a new list which contains the common elements between the 2 given lists. Is it sorting and then comparing

Re: [algogeeks] stack

2010-06-11 Thread Anurag Sharma
Is it without having the need to shift elements at all? Anurag Sharma On Fri, Jun 11, 2010 at 3:41 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: Give an algorithm to implement n stacks in an array... take care of the empty space too i.e no overflow shld occur if there is eny empty space

Re: [algogeeks] hashing

2010-06-10 Thread Anurag Sharma
. Anurag Sharma On Thu, Jun 10, 2010 at 5:16 AM, sharad kumar aryansmit3...@gmail.comwrote: can u reduce the size by making use of bucket sort On Wed, Jun 9, 2010 at 5:01 PM, sharad sharad20073...@gmail.com wrote: I have a stream of numbers coming one by one from a computer generated

Re: [algogeeks] Re: ds

2010-06-10 Thread Anurag Sharma
nice algo! Anurag Sharma On Wed, Jun 9, 2010 at 11:23 PM, souravsain souravs...@gmail.com wrote: Guys We can solve this in O(n) time like this: Let me say total elements in array is 2N such that 1 to N are a's and N +1 to 2N (which I will again refer to as 1 to N) are b's Observation

Re: [algogeeks] Re: ds

2010-06-09 Thread Anurag Sharma
Its not O(n) time. Anurag Sharma On Wed, Jun 9, 2010 at 5:46 PM, Jitendra Kushwaha jitendra.th...@gmail.comwrote: here is a sel explainatory algo given: abcd1234 abc1d234 ab1c2d34 a1b2c3d4 here is the link for the code : http://codepad.org/SZnufGc6 -- Regards Jitendra Kushwaha

Re: [algogeeks] level order traversal

2010-06-09 Thread Anurag Sharma
Do you have 'parent pointers' stored at every node? Anurag Sharma On Wed, Jun 9, 2010 at 2:26 PM, sharad sharad20073...@gmail.com wrote: can any one tell me how to code for vertical level traversal of a binary tree? 1

Re: [algogeeks] Re: constraints satisfied?

2010-06-09 Thread Anurag Sharma
) and whenever an overwrite occurs we will know that its not possible to satisfy all constraints. Although this will shoot up our time complexity to O(n^3) because of Floyd Warshal algorithm. Comments welcome. Anurag Sharma On Wed, Jun 9, 2010 at 3:42 PM, jaladhi dave jaladhi.k.d

Re: [algogeeks] level order traversal

2010-06-09 Thread Anurag Sharma
!marked[j]; j = (j - 1) / 2) { printf([%d], arr[j]); marked[j] = true; } } } Anurag Sharma On Wed, Jun 9, 2010 at 9:31 PM, sharad kumar sharad20073...@gmail.comwrote: 1

Re: [algogeeks] hashing

2010-06-09 Thread Anurag Sharma
. Anurag Sharma On Wed, Jun 9, 2010 at 9:29 PM, sharad kumar sharad20073...@gmail.comwrote: @ anurag we can do operation only at bit level sowe will need o(32n) although it is also O(n) bt if word size is more then its quite inefficient so suggest 4 that -- You received this message

Re: [algogeeks] Re: identify the recurring part for a given decimal no

2010-06-09 Thread Anurag Sharma
multiply the original number x=23.34563456 Anurag Sharma On Wed, Jun 9, 2010 at 10:36 PM, Veer Sharma thisisv...@rediffmail.comwrote: One question: No x = 23.34563456 temp = x X 10 = 233.4563456 temp = temp - x = 210.11071104 decimal part zero? No. Now multiply the no. with 100. Which

Re: [algogeeks] min no of policemen

2010-06-08 Thread Anurag Sharma
Can you expain edge of the tree. I could not get that. Anurag Sharma On Tue, Jun 8, 2010 at 5:53 AM, sharad kumar aryansmit3...@gmail.comwrote: for placing police man we can use bellman ford bfs.or even make use of topological sort. On Mon, Jun 7, 2010 at 9:59 PM, divya sweetdivya

Re: [algogeeks] ds

2010-06-07 Thread Anurag Sharma
@anand. Perhaps, its not correct. Does not work for larger inputs. Anurag Sharma On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote: Here is my approach is o(n). http://codepad.org/YAFfZpxO http://codepad.org/YAFfZpxO On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar

Re: [algogeeks] Re: Find Max Number of Elephants

2010-06-06 Thread Anurag Sharma
I am sorry for the link if it caused any confusion. It was just a part of the signature. Kindly disregard the link in this context. Anurag Sharma On Sun, Jun 6, 2010 at 7:55 AM, Minotauraus anike...@gmail.com wrote: I think you can do this in O(n) time. Feel free to correct me where I'm

Re: [algogeeks] Find Max Number of Elephants

2010-06-05 Thread Anurag Sharma
use interval trees. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Sat, Jun 5, 2010 at 6:16 PM, amit amitjaspal...@gmail.com wrote: Maximum number of elephants alive Hello guyz, Every elephant has a birth_time and a death_time. Given N Elephants with birth times and death times

Re: [algogeeks] Check if 2 linked lists are identical

2010-06-03 Thread Anurag Sharma
But perhaps the elements in lists may not be in order. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Thu, Jun 3, 2010 at 6:38 PM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: simple in place O(n lg n) solution. Choose a pivot in first array and partition it like in quicksort. Find

Re: [algogeeks] Check if 2 linked lists are identical

2010-06-02 Thread Anurag Sharma
You can construct some kind of Search Tree like BST from the first list and search for every element in the second list in that search Tree. O(NlogN) time Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Wed, Jun 2, 2010 at 6:18 AM, sharad kumar aryansmit3...@gmail.comwrote

Re: [algogeeks] Re: Implementing 2 stacks within a single linear array

2010-06-02 Thread Anurag Sharma
will get maximum size of N/3 where N is sizeof array. Or we can start 1st stack from starting, 2nd from end and 3rd from the middle. I cant think of any other implementation of 3 stacks where you can survive without shifting the elements and efficiently using the array space. Comments welcome. Anurag

Re: [algogeeks] Can you solve this?

2010-05-31 Thread Anurag Sharma
=13,sumB=14 now since the elements are not balanced in 2 arrays we need to transfer lowest the (4-2)/2= 1 element from teamB to teamA i.e. transfer element 2 in this case final result: teamA={12,1,2}, teamB={5,4,3} sumA=15, sumB=12 difference is 3 unlike 9 in your case. Anurag

Re: [algogeeks] Re: Can you solve this?

2010-05-31 Thread Anurag Sharma
ya I guess its the same problem.. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Mon, May 31, 2010 at 10:00 AM, W Karas wka...@yahoo.com wrote: Is this the same problem as: http://groups.google.com/group/algogeeks/browse_frm/thread/26c31cc2530a88e1# ? Or can the teams have

Re: [algogeeks] Re: Can you solve this?

2010-05-31 Thread Anurag Sharma
Well, in that case, then just forget the balancing the number of elements in the 2 teams portion of my solution above :) Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Mon, May 31, 2010 at 10:38 AM, Nik_nitdgp nikhil.bhoja...@gmail.comwrote: This problem is like 2 processor job

Re: [algogeeks] Re: Google telephone interview question

2010-05-29 Thread Anurag Sharma
Is it necessary that the sectors allocated to the file are strictly in increasing number? Can file2 have sectors like *sec12-sec10-null* ??? Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Sat, May 29, 2010 at 12:37 AM, Atul Kumar atul...@gmail.com wrote: Sorry the example should

Re: [algogeeks] question

2010-05-17 Thread Anurag Sharma
when we find the sum increasing as the array is already sorted. Let me know if there is still some issue in it. Regards, Anurag Sharma On Sun, May 16, 2010 at 9:26 PM, Navin Naidu navinmna...@gmail.com wrote: @anurag: wont work, consider the following case: -99 0 2 -1 99 On Sun, May 16

Re: [algogeeks] question

2010-05-17 Thread Anurag Sharma
oops! Anurag Sharma On Mon, May 17, 2010 at 5:00 PM, Navin Naidu navinmna...@gmail.com wrote: @anurag: -99 -2 -1 3 +99 The min sum (=0) for value pair (-99, 99) Now skip, +99 and -99, so -1 will be selected: (99, -99, -1) = -1 Actual result: -2, -1, 3 : 0 On Mon, May 17, 2010

Re: [algogeeks] partion of array

2010-05-15 Thread Anurag Sharma
|/2 (=1) element from B to A and we get A={23,2,1,3} and B={7,6,5,4} and difference of sums=29-22=7 Let me know if theres something wrong with this approach. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Fri, May 14, 2010 at 1:51 PM, divya sweetdivya@gmail.com wrote: Algorithm

Re: [algogeeks] question

2010-05-15 Thread Anurag Sharma
the current number yields the sum closest to zero. Thats what your third number is. It takes n log(n) + n^2 + n time which is O(n^2) and O(1) extra memory Correct me if I am wrong. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Mon, May 3, 2010 at 6:18 PM, jalaj jaiswal jalaj.jaiswa

Re: [algogeeks] Finding youngest common ancestor of two nodes in a binary tree

2010-04-08 Thread Anurag Sharma
-right, B)) return root; node* left = getCommonAncestor(root-left, A, B); node* right= getCommonAncestor(root-right, A, B); if(left !=NULL) return left; if(right !=NULL) return right; return NULL; } Hope this helps you. Comments welcome -- Anurag Sharma http://anuragsharma

Re: [algogeeks] Finding youngest common ancestor of two nodes in a binary tree

2010-04-08 Thread Anurag Sharma
Well Atul, Mind it, its not a Binary Search Tree, its just a Binary Tree. So this concept of the elements in left sub tree all having the value less than the current node and similar for the right subtree will not stand here. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Thu, Apr 8

Re: [algogeeks] Re: Finding youngest common ancestor of two nodes in a binary tree

2010-04-08 Thread Anurag Sharma
on my blog. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Thu, Apr 8, 2010 at 5:32 PM, Dave dave_and_da...@juno.com wrote: @Anurag. I like your algorithm, but observe some deficiencies... A could be on the right subtree and B on the left, as well. And what if B is a descendent

Re: [algogeeks] Re: Finding youngest common ancestor of two nodes in a binary tree

2010-04-08 Thread Anurag Sharma
@Rahul, The Tree is not Binary Search Tree. Anurag Sharma http://anuragsharma-sun.blogspot.com/ On Thu, Apr 8, 2010 at 6:52 PM, Rahul Singh rahu...@gmail.com wrote: Perform inorder traverse for both the node. match element by element the 2 strings and when first time the string deviates

Re: [algogeeks] Digest for algogeeks@googlegroups.com - 17 Messages in 3 Topics

2010-04-02 Thread Anurag Sharma
Here is what you want exactly: http://anuragsharma-sun.blogspot.com/2010/03/converting-bst-to-circular-doubly.html Hope it helps -Anurag Sharma On Thu, Apr 1, 2010 at 4:54 PM, algogeeks+nore...@googlegroups.comalgogeeks%2bnore...@googlegroups.com wrote: Today's Topic Summary Group: http