Re: to merge two binary tree



sudharsan wrote:
cud you give me logic to merge two sorted binary trees.I mean which
node has to be taken as root node in the new tree ...etc

This isn't a C programming question as such.
Surely there must be an algorithm in Knuth.
The root node of the merge will in general
not be either of the original root nodes.
If you want to develop your own algorithm,
the easy way is to just start with a new
empty tree and traverse each of the input
trees, inserting (moving) each input node
into the new tree being formed, according
to a usual binary-tree insertion algorithm.
Presumably that isn't as efficient as an
optimized algorithm, but unless your app
calls for a lot of tree merging it should
suffice. (An optimal algorithm would
presumably just insert the root node of
the second input at the appropriate point
in the first (binary tree insertion) and
then perform a tree "rebalancing" action.)
--
comp.lang.c.moderated - moderation address: clcm@xxxxxxxxxxxx -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
.



Relevant Pages

  • Re: Trie data structure
    ... tree shows what key it is associated with..." ... It will contain the partial key "i". ... Its grandparent will have an empty partial key - the root node. ... As the lookup algorithm example on the wiki page describes, ...
    (comp.lang.ruby)
  • Re: I thought this should work :-(
    ... within the tree is a highly unusual, and highly suspect, design. ... There is substantial amount of functionality ... My tree is similar to the one mentioned for Windows Explorer. ... root node that has some of the functionality of subnodes but also has ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Binqry Tree sort
    ... In addition we have a network as a parallel ... But the processors which I want to use in my bianry tree architecture ... The root node has no bottle neck becasue it just receives data from its ...
    (comp.programming)
  • RE: Newbie: Trouble accessing all nodes in a tree view
    ... My tree has a single root node named ... > a new node at a deep level on the tree. ... > listed in the collection is the root node Clients. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Root and leaf node from a hierarchical tree.
    ... Tree strucutres can have any arbitrary depth. ... | Root node has parent_id as null. ... | rootB B-child1 ... | achieve the result by just writing a sql statement. ...
    (comp.databases.oracle.server)