Well I dont see how that is asymtotically better. The lowest level can have upto n/2 nodes of complete tree. So both the methods would still be O(n) .
-Dhyanesh On 5/8/06, akshay ranjan <[EMAIL PROTECTED]> wrote: > I think that this tree would always be balanced till one level from the > leaves. so employing bfs wouldn't be optimum. you can check if the tree is > full or not at the last level . if it is not full insert at that point , in > case if the tree is full you need to insert in the leftmost node in the next > level > > > On 5/8/06, Dhyanesh <[EMAIL PROTECTED]> wrote: > > > > Do a simple BFS traversal of the tree. The first node which does not > > have two childs is where you want to insert the new node. If it has no > > childs then the new node is the left child. If it has 1 child then the > > new node is the right child. > > > > -Dhyanesh > > > > On 5/8/06, shishir <[EMAIL PROTECTED]> wrote: > > > > > > Hi, > > > I am looking for a method for left to right insertion in a binary tree( > > > mind it, its not BST am talking about). A simple binary tree where > > > every root has not more than two childs and the insertion is always > > > done starting from the leftmost side of any given node. > > > > > > 13 > > > / \ > > > 27 54 > > > / \ / \ > > > 23 42 > > > > > > For eg in the above case the next node should be inserted as the left > > > most child of 54. > > > Let me know if there's any doubt regarding the question. > > > > > > ~Shishir > > > > > > > > > > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---