Finding Index of a Node in a Huffman Tree / BST-ish









up vote
1
down vote

favorite












Assume we have a tree of nodes that hold string values in them. How would I go about traversing the tree and spitting out an index of a specific node if I had a tree like this? The numbers I drew inside the circles would be the index I want (especially 12 or 13).BST










share|improve this question



























    up vote
    1
    down vote

    favorite












    Assume we have a tree of nodes that hold string values in them. How would I go about traversing the tree and spitting out an index of a specific node if I had a tree like this? The numbers I drew inside the circles would be the index I want (especially 12 or 13).BST










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Assume we have a tree of nodes that hold string values in them. How would I go about traversing the tree and spitting out an index of a specific node if I had a tree like this? The numbers I drew inside the circles would be the index I want (especially 12 or 13).BST










      share|improve this question















      Assume we have a tree of nodes that hold string values in them. How would I go about traversing the tree and spitting out an index of a specific node if I had a tree like this? The numbers I drew inside the circles would be the index I want (especially 12 or 13).BST







      java binary-search-tree






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 2:17

























      asked Nov 11 at 0:56









      King Arthur the Third

      234




      234






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          The tree you are showing is not a binary search tree. The central property of a binary search tree that allows it to be searched efficiently is that the left descendants of a node are smaller, and the right descendants bigger than the node itself (in terms of the index value).



          If you have a proper binary search tree, you can find a node with given index by comparing with nodes and following the corresponding branch, starting with the root.






          share|improve this answer




















          • Quoting my question: "Assume we have a tree of nodes that hold string values in them" and "The numbers I drew inside the circles would be the index I want (especially 12 or 13)."
            – King Arthur the Third
            Nov 11 at 1:50










          • I'm working on an assignment that is dealing with more of a Huffman Tree like structure
            – King Arthur the Third
            Nov 11 at 1:53











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244895%2ffinding-index-of-a-node-in-a-huffman-tree-bst-ish%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          The tree you are showing is not a binary search tree. The central property of a binary search tree that allows it to be searched efficiently is that the left descendants of a node are smaller, and the right descendants bigger than the node itself (in terms of the index value).



          If you have a proper binary search tree, you can find a node with given index by comparing with nodes and following the corresponding branch, starting with the root.






          share|improve this answer




















          • Quoting my question: "Assume we have a tree of nodes that hold string values in them" and "The numbers I drew inside the circles would be the index I want (especially 12 or 13)."
            – King Arthur the Third
            Nov 11 at 1:50










          • I'm working on an assignment that is dealing with more of a Huffman Tree like structure
            – King Arthur the Third
            Nov 11 at 1:53















          up vote
          0
          down vote













          The tree you are showing is not a binary search tree. The central property of a binary search tree that allows it to be searched efficiently is that the left descendants of a node are smaller, and the right descendants bigger than the node itself (in terms of the index value).



          If you have a proper binary search tree, you can find a node with given index by comparing with nodes and following the corresponding branch, starting with the root.






          share|improve this answer




















          • Quoting my question: "Assume we have a tree of nodes that hold string values in them" and "The numbers I drew inside the circles would be the index I want (especially 12 or 13)."
            – King Arthur the Third
            Nov 11 at 1:50










          • I'm working on an assignment that is dealing with more of a Huffman Tree like structure
            – King Arthur the Third
            Nov 11 at 1:53













          up vote
          0
          down vote










          up vote
          0
          down vote









          The tree you are showing is not a binary search tree. The central property of a binary search tree that allows it to be searched efficiently is that the left descendants of a node are smaller, and the right descendants bigger than the node itself (in terms of the index value).



          If you have a proper binary search tree, you can find a node with given index by comparing with nodes and following the corresponding branch, starting with the root.






          share|improve this answer












          The tree you are showing is not a binary search tree. The central property of a binary search tree that allows it to be searched efficiently is that the left descendants of a node are smaller, and the right descendants bigger than the node itself (in terms of the index value).



          If you have a proper binary search tree, you can find a node with given index by comparing with nodes and following the corresponding branch, starting with the root.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 1:25









          Henning Koehler

          1,100610




          1,100610











          • Quoting my question: "Assume we have a tree of nodes that hold string values in them" and "The numbers I drew inside the circles would be the index I want (especially 12 or 13)."
            – King Arthur the Third
            Nov 11 at 1:50










          • I'm working on an assignment that is dealing with more of a Huffman Tree like structure
            – King Arthur the Third
            Nov 11 at 1:53

















          • Quoting my question: "Assume we have a tree of nodes that hold string values in them" and "The numbers I drew inside the circles would be the index I want (especially 12 or 13)."
            – King Arthur the Third
            Nov 11 at 1:50










          • I'm working on an assignment that is dealing with more of a Huffman Tree like structure
            – King Arthur the Third
            Nov 11 at 1:53
















          Quoting my question: "Assume we have a tree of nodes that hold string values in them" and "The numbers I drew inside the circles would be the index I want (especially 12 or 13)."
          – King Arthur the Third
          Nov 11 at 1:50




          Quoting my question: "Assume we have a tree of nodes that hold string values in them" and "The numbers I drew inside the circles would be the index I want (especially 12 or 13)."
          – King Arthur the Third
          Nov 11 at 1:50












          I'm working on an assignment that is dealing with more of a Huffman Tree like structure
          – King Arthur the Third
          Nov 11 at 1:53





          I'm working on an assignment that is dealing with more of a Huffman Tree like structure
          – King Arthur the Third
          Nov 11 at 1:53


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244895%2ffinding-index-of-a-node-in-a-huffman-tree-bst-ish%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          天津地下鉄3号線

          How to fill missing numeric if any value in a subset is missing, all other columns with the same subset are missing