Need an algorithm for creating an complete binary tree.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C-man

    Need an algorithm for creating an complete binary tree.

    Yeah, for some reason I can seem to find an algorithm that will simple but
    items into the tree in fashion such that a new leaf can't be added to a new
    level till all the leafs at the previous level are used. This would seem
    like an easy solution but I couldn't find one and I only could get it
    parsley working. Any body of a solution?


    Thanks


  • Mike Wahler

    #2
    Re: [OT, welcome msg, link] Need an algorithm for creating an complete binary tree.

    "C-man" <iamcleaver@sha w.ca> wrote in message
    news:pgv1c.3962 2$n17.16894@clg rps13...[color=blue]
    > Yeah, for some reason I can seem to find an algorithm that will simple but
    > items into the tree in fashion such that a new leaf can't be added to a[/color]
    new[color=blue]
    > level till all the leafs at the previous level are used. This would seem
    > like an easy solution but I couldn't find one and I only could get it
    > parsley working. Any body of a solution?[/color]

    Algorithms aren't topical here. Just the ISO standard C++ language.
    See: http://www.slack.net/~shiva/welcome.txt

    However:

    orithm+%22C%2B% 2B%22&btnG=Goog le+Search
    (that'll probably wrap, just paste it back together)

    Over 7,000 hits.

    You might want to try asking about this in an algorithms group
    or mailing list.

    -Mike


    Comment

    • Dietmar Kuehl

      #3
      Re: Need an algorithm for creating an complete binary tree.

      "C-man" <iamcleaver@sha w.ca> wrote:[color=blue]
      > Yeah, for some reason I can seem to find an algorithm that will simple but
      > items into the tree in fashion such that a new leaf can't be added to a new
      > level till all the leafs at the previous level are used. This would seem
      > like an easy solution but I couldn't find one and I only could get it
      > parsley working. Any body of a solution?[/color]

      What is your actual goal? Typically, for something like a search tree it is
      sufficient that the tree is reasonably balanced. For example, if the
      maximum height in each (sub)tree is at most twice the minimum height, you
      will get logarithmic access to all operations. And the corresponding
      condition is relatively easy to maintain using AVL- or Red-Black-Trees.

      The simplest approach to a fully balanced binary tree is probably using an
      array in the first place! You would use 'std::lower_bou nd()' to locate a
      position - be it for insertion or lookup. The container is, in this case,
      of course not node bound.
      --
      <mailto:dietmar _kuehl@yahoo.co m> <http://www.dietmar-kuehl.de/>
      Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.co m/>

      Comment

      Working...