Is there a name for this priority queue data structure?












2












$begingroup$


While watching a sports tournament, I noticed that the tournament tree looks a lot like a heap. I came up with the following data structure: A complete binary tree where the leaves are elements of some set, and each internal node is the $max$ of its two children. I came up with a BuildHeap algorithm that's $O(n)$, a GetMax algorithm that's $O(1)$, an Insert algorithm that's $O(log n)$, and a Delete algorithm that's $O(log n)$. The number of nodes in this "heap" is $2n-1$ where $n$ is the number of elements in the underlying set. The structure is simpler than a binary heap.



Is there a name for this data structure?










share|cite|improve this question











$endgroup$

















    2












    $begingroup$


    While watching a sports tournament, I noticed that the tournament tree looks a lot like a heap. I came up with the following data structure: A complete binary tree where the leaves are elements of some set, and each internal node is the $max$ of its two children. I came up with a BuildHeap algorithm that's $O(n)$, a GetMax algorithm that's $O(1)$, an Insert algorithm that's $O(log n)$, and a Delete algorithm that's $O(log n)$. The number of nodes in this "heap" is $2n-1$ where $n$ is the number of elements in the underlying set. The structure is simpler than a binary heap.



    Is there a name for this data structure?










    share|cite|improve this question











    $endgroup$















      2












      2








      2





      $begingroup$


      While watching a sports tournament, I noticed that the tournament tree looks a lot like a heap. I came up with the following data structure: A complete binary tree where the leaves are elements of some set, and each internal node is the $max$ of its two children. I came up with a BuildHeap algorithm that's $O(n)$, a GetMax algorithm that's $O(1)$, an Insert algorithm that's $O(log n)$, and a Delete algorithm that's $O(log n)$. The number of nodes in this "heap" is $2n-1$ where $n$ is the number of elements in the underlying set. The structure is simpler than a binary heap.



      Is there a name for this data structure?










      share|cite|improve this question











      $endgroup$




      While watching a sports tournament, I noticed that the tournament tree looks a lot like a heap. I came up with the following data structure: A complete binary tree where the leaves are elements of some set, and each internal node is the $max$ of its two children. I came up with a BuildHeap algorithm that's $O(n)$, a GetMax algorithm that's $O(1)$, an Insert algorithm that's $O(log n)$, and a Delete algorithm that's $O(log n)$. The number of nodes in this "heap" is $2n-1$ where $n$ is the number of elements in the underlying set. The structure is simpler than a binary heap.



      Is there a name for this data structure?







      data-structures terminology heaps priority-queues






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Jan 27 at 3:31









      Apass.Jack

      13.3k1939




      13.3k1939










      asked Jan 26 at 20:50









      man on laptopman on laptop

      34119




      34119






















          2 Answers
          2






          active

          oldest

          votes


















          6












          $begingroup$

          This is essentially a Segment tree which is a data structure that augments an array with a binary tree as you describe such that:




          • You have fast set and get at any index

          • You have fast "aggregate" queries on ranges

          • You can support fast update queries on ranges, for some combinations of updates and queries


          The $j$th node at height $k$ in the tree "summarizes" a subarray $[j*2^k, (j+1)*2^k)$ of the original array. Since each element of the array appears in only logarithmically many such subarrays, we can do updates in $O(log n)$ time.



          The range queries can use any associative operation. In your example the operation is $max$, but other examples include sum, product, even standard deviation (via sum and sum of squares).





          I originally called this a Fenwick Tree (aka Binary Indexed Tree), which is a similar structure but which compresses the tree into only exactly $n$ storage with no overhead(but loses access to the original array).






          share|cite|improve this answer











          $endgroup$













          • $begingroup$
            I think you're right and I confuse them all the time
            $endgroup$
            – Curtis F
            Jan 26 at 22:39






          • 3




            $begingroup$
            For clarification: a Segment tree also uses linear storage.
            $endgroup$
            – Jakube
            Jan 26 at 23:12



















          1












          $begingroup$

          You've just reinvented a range-query structure. This is an instance of the more general idea that, if you put all data at only the leaves of a binary tree, you can use internal nodes to represent substructures, and it will work for any kind of structure that can be recursively defined with an $O(1)$ recursive initialization.



          In this case, you can see that the structure is just an unordered set with a maximum, which is obviously $O(1)$ recursively definable. It is also clear that you can support Insert and DeleteMax and $O(1)$ GetMax, but not $O(log n)$ Search. Additionally, if you think a bit you should be able to figure out how to support $O(log n)$ MergeHeap.






          share|cite|improve this answer









          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "419"
            };
            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fcs.stackexchange.com%2fquestions%2f103444%2fis-there-a-name-for-this-priority-queue-data-structure%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            6












            $begingroup$

            This is essentially a Segment tree which is a data structure that augments an array with a binary tree as you describe such that:




            • You have fast set and get at any index

            • You have fast "aggregate" queries on ranges

            • You can support fast update queries on ranges, for some combinations of updates and queries


            The $j$th node at height $k$ in the tree "summarizes" a subarray $[j*2^k, (j+1)*2^k)$ of the original array. Since each element of the array appears in only logarithmically many such subarrays, we can do updates in $O(log n)$ time.



            The range queries can use any associative operation. In your example the operation is $max$, but other examples include sum, product, even standard deviation (via sum and sum of squares).





            I originally called this a Fenwick Tree (aka Binary Indexed Tree), which is a similar structure but which compresses the tree into only exactly $n$ storage with no overhead(but loses access to the original array).






            share|cite|improve this answer











            $endgroup$













            • $begingroup$
              I think you're right and I confuse them all the time
              $endgroup$
              – Curtis F
              Jan 26 at 22:39






            • 3




              $begingroup$
              For clarification: a Segment tree also uses linear storage.
              $endgroup$
              – Jakube
              Jan 26 at 23:12
















            6












            $begingroup$

            This is essentially a Segment tree which is a data structure that augments an array with a binary tree as you describe such that:




            • You have fast set and get at any index

            • You have fast "aggregate" queries on ranges

            • You can support fast update queries on ranges, for some combinations of updates and queries


            The $j$th node at height $k$ in the tree "summarizes" a subarray $[j*2^k, (j+1)*2^k)$ of the original array. Since each element of the array appears in only logarithmically many such subarrays, we can do updates in $O(log n)$ time.



            The range queries can use any associative operation. In your example the operation is $max$, but other examples include sum, product, even standard deviation (via sum and sum of squares).





            I originally called this a Fenwick Tree (aka Binary Indexed Tree), which is a similar structure but which compresses the tree into only exactly $n$ storage with no overhead(but loses access to the original array).






            share|cite|improve this answer











            $endgroup$













            • $begingroup$
              I think you're right and I confuse them all the time
              $endgroup$
              – Curtis F
              Jan 26 at 22:39






            • 3




              $begingroup$
              For clarification: a Segment tree also uses linear storage.
              $endgroup$
              – Jakube
              Jan 26 at 23:12














            6












            6








            6





            $begingroup$

            This is essentially a Segment tree which is a data structure that augments an array with a binary tree as you describe such that:




            • You have fast set and get at any index

            • You have fast "aggregate" queries on ranges

            • You can support fast update queries on ranges, for some combinations of updates and queries


            The $j$th node at height $k$ in the tree "summarizes" a subarray $[j*2^k, (j+1)*2^k)$ of the original array. Since each element of the array appears in only logarithmically many such subarrays, we can do updates in $O(log n)$ time.



            The range queries can use any associative operation. In your example the operation is $max$, but other examples include sum, product, even standard deviation (via sum and sum of squares).





            I originally called this a Fenwick Tree (aka Binary Indexed Tree), which is a similar structure but which compresses the tree into only exactly $n$ storage with no overhead(but loses access to the original array).






            share|cite|improve this answer











            $endgroup$



            This is essentially a Segment tree which is a data structure that augments an array with a binary tree as you describe such that:




            • You have fast set and get at any index

            • You have fast "aggregate" queries on ranges

            • You can support fast update queries on ranges, for some combinations of updates and queries


            The $j$th node at height $k$ in the tree "summarizes" a subarray $[j*2^k, (j+1)*2^k)$ of the original array. Since each element of the array appears in only logarithmically many such subarrays, we can do updates in $O(log n)$ time.



            The range queries can use any associative operation. In your example the operation is $max$, but other examples include sum, product, even standard deviation (via sum and sum of squares).





            I originally called this a Fenwick Tree (aka Binary Indexed Tree), which is a similar structure but which compresses the tree into only exactly $n$ storage with no overhead(but loses access to the original array).







            share|cite|improve this answer














            share|cite|improve this answer



            share|cite|improve this answer








            edited Jan 27 at 17:26

























            answered Jan 26 at 21:16









            Curtis FCurtis F

            450211




            450211












            • $begingroup$
              I think you're right and I confuse them all the time
              $endgroup$
              – Curtis F
              Jan 26 at 22:39






            • 3




              $begingroup$
              For clarification: a Segment tree also uses linear storage.
              $endgroup$
              – Jakube
              Jan 26 at 23:12


















            • $begingroup$
              I think you're right and I confuse them all the time
              $endgroup$
              – Curtis F
              Jan 26 at 22:39






            • 3




              $begingroup$
              For clarification: a Segment tree also uses linear storage.
              $endgroup$
              – Jakube
              Jan 26 at 23:12
















            $begingroup$
            I think you're right and I confuse them all the time
            $endgroup$
            – Curtis F
            Jan 26 at 22:39




            $begingroup$
            I think you're right and I confuse them all the time
            $endgroup$
            – Curtis F
            Jan 26 at 22:39




            3




            3




            $begingroup$
            For clarification: a Segment tree also uses linear storage.
            $endgroup$
            – Jakube
            Jan 26 at 23:12




            $begingroup$
            For clarification: a Segment tree also uses linear storage.
            $endgroup$
            – Jakube
            Jan 26 at 23:12











            1












            $begingroup$

            You've just reinvented a range-query structure. This is an instance of the more general idea that, if you put all data at only the leaves of a binary tree, you can use internal nodes to represent substructures, and it will work for any kind of structure that can be recursively defined with an $O(1)$ recursive initialization.



            In this case, you can see that the structure is just an unordered set with a maximum, which is obviously $O(1)$ recursively definable. It is also clear that you can support Insert and DeleteMax and $O(1)$ GetMax, but not $O(log n)$ Search. Additionally, if you think a bit you should be able to figure out how to support $O(log n)$ MergeHeap.






            share|cite|improve this answer









            $endgroup$


















              1












              $begingroup$

              You've just reinvented a range-query structure. This is an instance of the more general idea that, if you put all data at only the leaves of a binary tree, you can use internal nodes to represent substructures, and it will work for any kind of structure that can be recursively defined with an $O(1)$ recursive initialization.



              In this case, you can see that the structure is just an unordered set with a maximum, which is obviously $O(1)$ recursively definable. It is also clear that you can support Insert and DeleteMax and $O(1)$ GetMax, but not $O(log n)$ Search. Additionally, if you think a bit you should be able to figure out how to support $O(log n)$ MergeHeap.






              share|cite|improve this answer









              $endgroup$
















                1












                1








                1





                $begingroup$

                You've just reinvented a range-query structure. This is an instance of the more general idea that, if you put all data at only the leaves of a binary tree, you can use internal nodes to represent substructures, and it will work for any kind of structure that can be recursively defined with an $O(1)$ recursive initialization.



                In this case, you can see that the structure is just an unordered set with a maximum, which is obviously $O(1)$ recursively definable. It is also clear that you can support Insert and DeleteMax and $O(1)$ GetMax, but not $O(log n)$ Search. Additionally, if you think a bit you should be able to figure out how to support $O(log n)$ MergeHeap.






                share|cite|improve this answer









                $endgroup$



                You've just reinvented a range-query structure. This is an instance of the more general idea that, if you put all data at only the leaves of a binary tree, you can use internal nodes to represent substructures, and it will work for any kind of structure that can be recursively defined with an $O(1)$ recursive initialization.



                In this case, you can see that the structure is just an unordered set with a maximum, which is obviously $O(1)$ recursively definable. It is also clear that you can support Insert and DeleteMax and $O(1)$ GetMax, but not $O(log n)$ Search. Additionally, if you think a bit you should be able to figure out how to support $O(log n)$ MergeHeap.







                share|cite|improve this answer












                share|cite|improve this answer



                share|cite|improve this answer










                answered Jan 27 at 10:05









                user21820user21820

                1304




                1304






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Computer Science Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f103444%2fis-there-a-name-for-this-priority-queue-data-structure%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

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]