[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-12 Thread hc busy
I agree, this seems like freshman algo homework, ask TA for a hint. The algorithm I described previously works fine. and it's probly in one of the books anyways... U need something like a Potential function, and do some monkeying around with it and it all works out. On Feb 11, 10:04 pm, Sunny <[

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-11 Thread Sunny
Pls , you should not discuss your homework assignments on this group. : ( On Feb 11, 5:12 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > This is an exercise problem in the book "Introduction to Algorithms" > by CLR. Could any one come up with an algorithm to do it. --~--~-~--~~-

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-11 Thread Karthik Singaram Lakshmanan
keep track of the last node you visited... if you are coming from the left child, go to the right child... if you are coming from the right child, go to the parent... thats the brief idea... --~--~-~--~~~---~--~~ You received this message because you are subscribed

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-11 Thread Karthik Singaram Lakshmanan
assume parent pointers...then you can --~--~-~--~~~---~--~~ 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

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-11 Thread Ajinkya Kale
I personally dont think so. 2008/2/11 Pradeep Muthukrishnan <[EMAIL PROTECTED]>: > Is it even possible to do taht in constant space? > > 2008/2/11 [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > > > > Thanks for all the effort. Sorry, I should have mentioned it earlier. > > But, we are asked to do it wi

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-11 Thread Pradeep Muthukrishnan
Is it even possible to do taht in constant space? 2008/2/11 [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > > Thanks for all the effort. Sorry, I should have mentioned it earlier. > But, we are asked to do it without modifying the tree in any manner > and using no more than a constant space outside the

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-11 Thread [EMAIL PROTECTED]
Thanks for all the effort. Sorry, I should have mentioned it earlier. But, we are asked to do it without modifying the tree in any manner and using no more than a constant space outside the tree. On Feb 11, 8:17 am, "phani bandaru" <[EMAIL PROTECTED]> wrote: > Use inorder traversal without rec

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-11 Thread phani bandaru
Use inorder traversal without recursion. On 2/11/08, James Fang <[EMAIL PROTECTED]> wrote: > > > Use a queue, assume the root of the binary tree : pRoot; > Below is the pseudo code: > > enQueue(pRoot); > While( queue not empty ) > { >pNode = outQueue(); >print(pNode); >if(pNode->left)

[algogeeks] Re: a non-recursive algorithm that prints all the nodes of a binary tree in O(n)

2008-02-10 Thread James Fang
Use a queue, assume the root of the binary tree : pRoot; Below is the pseudo code: enQueue(pRoot); While( queue not empty ) { pNode = outQueue(); print(pNode); if(pNode->left) { enQueue(pNode->left); } if(pNode->right) { enQueue(pNode->right); } }