Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. binary trees

binary trees

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amr Mohammad87
    wrote on last edited by
    #1

    I've read the following statement and I cannot understand something within it "In all binary trees, there are at most 2^i nodes at level i + 1" what I cannot understand is that tree's levels start at level 0, however, if we apply what is written in this statement there will be no level 0 at all as it says level i + 1 which mean 0 + 1 = level 1, 1 + 1 = level 2, etc. So is this statement wrong?!!! or I am missing something?!!!

    CPalliniC 1 Reply Last reply
    0
    • A Amr Mohammad87

      I've read the following statement and I cannot understand something within it "In all binary trees, there are at most 2^i nodes at level i + 1" what I cannot understand is that tree's levels start at level 0, however, if we apply what is written in this statement there will be no level 0 at all as it says level i + 1 which mean 0 + 1 = level 1, 1 + 1 = level 2, etc. So is this statement wrong?!!! or I am missing something?!!!

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Where did you read that? Here[^], for instance, is stated:

      In general, each level of a binary tree can have, at most, 2N nodes, where N is the level of the tree

      In testa che avete, signor di Ceprano?

      A 1 Reply Last reply
      0
      • CPalliniC CPallini

        Where did you read that? Here[^], for instance, is stated:

        In general, each level of a binary tree can have, at most, 2N nodes, where N is the level of the tree

        A Offline
        A Offline
        Amr Mohammad87
        wrote on last edited by
        #3

        I read it in 2 books "Data Structures Through C in Depth" and "Data Structures and Algorithms in C++, 4th Edition" and even the link you gave to me saying "The root of the tree, therefore, is at level 0" which means that tree's level starts at 0. So I am confused because those books also saying that tree's level starts at 0?!!!

        CPalliniC 1 Reply Last reply
        0
        • A Amr Mohammad87

          I read it in 2 books "Data Structures Through C in Depth" and "Data Structures and Algorithms in C++, 4th Edition" and even the link you gave to me saying "The root of the tree, therefore, is at level 0" which means that tree's level starts at 0. So I am confused because those books also saying that tree's level starts at 0?!!!

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Well, that's correct if you say 2N (instead of 2(N-1)) as maximum number of nodes at level N.

          In testa che avete, signor di Ceprano?

          A 2 Replies Last reply
          0
          • CPalliniC CPallini

            Well, that's correct if you say 2N (instead of 2(N-1)) as maximum number of nodes at level N.

            A Offline
            A Offline
            Amr Mohammad87
            wrote on last edited by
            #5

            I know it is correct to say 2^N, however, to say for level N+1 is what makes me confused because tree's level starts at level 0 which mean that N = 0 so if we apply the above statement it will be 2^0 for level 0 + 1 which means 1 node for level number 1 I hope you get what I meant.

            CPalliniC 1 Reply Last reply
            0
            • CPalliniC CPallini

              Well, that's correct if you say 2N (instead of 2(N-1)) as maximum number of nodes at level N.

              A Offline
              A Offline
              Amr Mohammad87
              wrote on last edited by
              #6

              I know it is correct to say 2^N, however, to say for level N+1 is what makes me confused because tree's level starts at level 0 which mean that N = 0 so if we apply the above statement it will be 2^0 for level 0 + 1 which means 1 node for level number 1 I hope you get what I meant

              1 Reply Last reply
              0
              • A Amr Mohammad87

                I know it is correct to say 2^N, however, to say for level N+1 is what makes me confused because tree's level starts at level 0 which mean that N = 0 so if we apply the above statement it will be 2^0 for level 0 + 1 which means 1 node for level number 1 I hope you get what I meant.

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7
                  \*        Level 0         2^0 = 1 node
                 / \\
                /   \\
                

                / \
                * * Level 1 2^1 = 2 nodes
                / \ / \
                * * * * Level 2 2^2 = 4 nodes

                It is 2N for level N. If you find written 2N-1 then levels are numbered differently, starting from 1 (instead of 0).

                In testa che avete, signor di Ceprano?

                A 1 Reply Last reply
                0
                • CPalliniC CPallini
                    \*        Level 0         2^0 = 1 node
                   / \\
                  /   \\
                  

                  / \
                  * * Level 1 2^1 = 2 nodes
                  / \ / \
                  * * * * Level 2 2^2 = 4 nodes

                  It is 2N for level N. If you find written 2N-1 then levels are numbered differently, starting from 1 (instead of 0).

                  A Offline
                  A Offline
                  Amr Mohammad87
                  wrote on last edited by
                  #8

                  Thanks for your reply :) I just get confused a little bit as some books state that level start at 0 and others state that level starts at 1. We need a unified solution between those authors :)

                  CPalliniC 1 Reply Last reply
                  0
                  • A Amr Mohammad87

                    Thanks for your reply :) I just get confused a little bit as some books state that level start at 0 and others state that level starts at 1. We need a unified solution between those authors :)

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #9

                    :) You are welcome.

                    In testa che avete, signor di Ceprano?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups