[algogeeks] Re: Binary tree to LL

2010-08-30 Thread Giri
@albert:
itz enough to make the right pointer to point to the next node.. no
need that left should point to the previous node..

On Aug 30, 8:14 am, Chonku  wrote:
> @albert
> I am not forming a separate list. My assumption was that next pointer is
> present in the node. But I will try to post a solution with only left and
> right pointers.
>
> On Mon, Aug 30, 2010 at 12:10 AM, albert theboss 
> wrote:
>
>
>
> > @Chonku:
>
> > you cant use "next" pointer in that...
>
> > you have to make link list such that right ptr points to next node
>
> > and left pointer to prev node
>
> > Am i right???
> > correct me if i am wrong.
>
> > --
> >  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+unsubscr...@googlegroups.com > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Binary tree to LL

2010-08-28 Thread Giri
@Chonku:
yours is wrong. consider the given ex,.
       50
     /     \
  25      60
 /     \     /  \
5    30  55  75

5 will become head. 5->next=25. 25->next=30. then 25 will be returned
up.
so 25->next=50. which is wrong

On Aug 26, 11:36 pm, Chonku  wrote:
> At first, store the pointer to the first node in inorder traversal (in this
> case 5) because its going to be the head of the list.
> Then use the following logic.
>
> flattenTree(TreeNode node) {
>     if (node is leaf node)
>        return node;
>
>     if (node.left exists) then
>         flattenTree(node.left)->next = node;
>
>      if (node.right exists) then
>         node->next = flattenTree(node.right);
>
>       return node;
>
> }
>
> On Thu, Aug 26, 2010 at 11:07 PM, Yan Wang wrote:
>
>
>
> > I can only figure out the inorder traversal...
>
> > On Thu, Aug 26, 2010 at 9:59 AM, krazee koder 
> > wrote:
> > > Give all possible methods to flatten a binary tree to a linked list.
>
> > > for eg.
>
> > >       50
> > >     /     \
> > >  25      60
> > > /     \     /  \
> > > 5    30  55  75
>
> > > should be flattened to  5->25->30->50->55->60->75
>
> > > PS: note that the tree should be converted to the LL and no separate
> > > LL should be formed.
>
> > > --
> > > 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+unsubscr...@googlegroups.com > .com>
> > .
> > > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > 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+unsubscr...@googlegroups.com > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: BST Problem

2010-08-25 Thread Giri
@arvind:
had i knwn would hv posted it

On Aug 23, 8:59 am, "R.ARAVINDH"  wrote:
> @giri:
>
> can u post d correct answer??

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: BFS

2010-08-25 Thread Giri
hi Chi,

I didnt mean any disrespect to others. Thought I neednt be too
formal.Anyways sorry for the language.

On Aug 22, 9:57 pm, Chi  wrote:
> Hi Giri,
>
> I don't think you can ask for help this way. By stack or recursion can
> mean you are looking for a linear solution, too. Next time you should
> be more precise in your question and I don't think this leet speech
> will help you much. Although some can graps the sound, but it is hard
> to read, and not very respectfull to the others.
>
> That's my opinion.
>
> Kind regards,
>
> Chi
>
> On Aug 22, 6:20 pm, Giri  wrote:
>
>
>
> > by stacks i meant the usage of extra space.. recursion stack is
> > handled by the OS.. so it doesnt bother.. ok
>
> > On Aug 22, 1:08 pm, "R.ARAVINDH"  wrote:
>
> > > @manohar and @giri::
>
> > > doesn recursion itself use stacks( implicitly)??
>
> > > On Aug 18, 9:26 pm, Giri  wrote:
>
> > > > @manohar: thnks man.. this solution would be apt..
>
> > > > if there's any better algo which doesn't use an extra stack or queue,
> > > > but does the purpose in recursion, do post it..
>
> > > > On Aug 18, 8:01 am, Manjunath Manohar 
> > > > wrote:
>
> > > > > Tree *node
> > > > > for(i=1;i<=height;i++)
> > > > > {
> > > > >    levelorder(node,i);}
>
> > > > > void levelorder(Tree *node,int level)
> > > > > {
> > > > >    if(level==1)
> > > > >      printf(node->value);
> > > > >   else
> > > > >      levelorder(node->left,level-1)
> > > > >      levelorder(node->right,level-1);
>
> > > > > }

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: BST Problem

2010-08-22 Thread Giri
frnd check ur code.. t contains much errors..
consider the following eg.:
k=5;3
   1 4
 2 5

On Aug 22, 2:30 pm, "R.ARAVINDH"  wrote:
> can v do like  this???
>
> findnodes(root,sum)
> {
> if(root==abs(sum-root->data))
> print (the data is root->data, sum-(root->data));
> else
> if(rootdata))
> findnodes(root->right,sum-root->data)
> else if(root>abs(sum-root->data))
> findnodes(root->left,sum-root->data)
> else if(root->left==NULL || root->right==NULL) print(root,sum-root);
>
>
>
> }

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: BFS

2010-08-22 Thread Giri
by stacks i meant the usage of extra space.. recursion stack is
handled by the OS.. so it doesnt bother.. ok

On Aug 22, 1:08 pm, "R.ARAVINDH"  wrote:
> @manohar and @giri::
>
> doesn recursion itself use stacks( implicitly)??
>
> On Aug 18, 9:26 pm, Giri  wrote:
>
>
>
> > @manohar: thnks man.. this solution would be apt..
>
> > if there's any better algo which doesn't use an extra stack or queue,
> > but does the purpose in recursion, do post it..
>
> > On Aug 18, 8:01 am, Manjunath Manohar 
> > wrote:
>
> > > Tree *node
> > > for(i=1;i<=height;i++)
> > > {
> > >    levelorder(node,i);}
>
> > > void levelorder(Tree *node,int level)
> > > {
> > >    if(level==1)
> > >      printf(node->value);
> > >   else
> > >      levelorder(node->left,level-1)
> > >      levelorder(node->right,level-1);
>
> > > }

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Longest Palindromic Substring

2010-08-22 Thread Giri
urs s correct 1ly for few cases.. but in the following case it doesnt
give the longest seq:
abadabac
here 'aba' will be printed and not 'abadaba', which s d correct ans

On Aug 22, 5:18 am, venkatesan B 
wrote:
> use stackpush one by one element before compare to top 2 element in stack {if 
> same then pop element and compare next char of string with top char in 
> stackif same continue otherwise clear stack}else{push element to stack}
> if wrong correct me

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: BFS

2010-08-18 Thread Giri
@manohar: thnks man.. this solution would be apt..

if there's any better algo which doesn't use an extra stack or queue,
but does the purpose in recursion, do post it..

On Aug 18, 8:01 am, Manjunath Manohar 
wrote:
> Tree *node
> for(i=1;i<=height;i++)
> {
>    levelorder(node,i);}
>
> void levelorder(Tree *node,int level)
> {
>    if(level==1)
>      printf(node->value);
>   else
>      levelorder(node->left,level-1)
>      levelorder(node->right,level-1);
>
>
>
> }

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: BFS

2010-08-17 Thread Giri
the point here is not the language.. when you could understand what
those words mean, it serves the purpose.. then sorry itz Breadth First
Traversal ofa tree without using queue.. got it?!

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] BFS

2010-08-17 Thread Giri
Cud any1 tell hw 2 implement BFS of a tree without queue?!

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] BFS

2010-08-17 Thread Giri
Cud any1 tell me hw to implement BFS without a queue?!

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.