Thread: leafs of binary complete tree

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    leafs of binary complete tree

    Hi guys, I'm wondering why the leafs of binary complete tree is always satisfying the property of min/max heap , and we are saying that immediately if we arrive a leaf then it satisfies the property of min/max heap, why?! may anyone please explain and elaborate the reason ..


    thanks in advance to the helpers

  2. #2
    Registered User
    Join Date
    Dec 2018
    Posts
    38
    Post a complete program that demonstrates the problem.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by RyanC
    I'm wondering why the leafs of binary complete tree is always satisfying the property of min/max heap , and we are saying that immediately if we arrive a leaf then it satisfies the property of min/max heap, why?!
    You might want to start by answering these questions for yourself:
    • What is a "binary complete tree"?
    • What is a "min/max heap"?
    • What is this property that you refer to?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Banned
    Join Date
    Apr 2015
    Posts
    596
    1. It's binary tree that's in every level all the positions are filled with nodes.
    2. Min heap is : the valur of the root is greater than it's children.
    3. I don't know why its trivial thats the leafs are satisfying minmum heap property. Meaning they are trivially min heap

  5. #5
    Banned
    Join Date
    Apr 2015
    Posts
    596
    The definition of min heap is: if there's children, then the children of a root is smaller than the root(its parent) , so how we get the conclusion that when there's no children(root is a leaf) then its in trivially min heap?!
    In math if A->B then if A doesn't occur, all possibilities are accepted ! so here there's a root which doesn't have children, then we can say that root is min heap also there's a possibility to say it's not a min heap because the condition A doesn't occur, then all possibilities are accepted

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by RyanC
    1. It's binary tree that's in every level all the positions are filled with nodes.
    That does not describe a complete binary tree.

    Quote Originally Posted by RyanC
    2. Min heap is : the valur of the root is greater than it's children.
    That incompletely describes a max heap. I was hoping that you would list in detail both the properties of a min (or max) heap, and then in your next answer explain which one you were talking about and why.

    Quote Originally Posted by RyanC
    3. I don't know why its trivial thats the leafs are satisfying minmum heap property. Meaning they are trivially min heap
    I asked "what is this property that you refer to?", not what are you confused about.

    Quote Originally Posted by RyanC
    so how we get the conclusion that when there's no children(root is a leaf) then its in trivially min heap?!
    I think you expressed this really poorly in posts #1 and #4. Instead of talking about "the leafs of binary complete tree is always satisfying the property of min/max heap" or even that "its trivial thats the leafs are satisfying minmum heap property", you should have asked: "why does a complete binary tree in which the root is a leaf trivially satisfy the other property of a min (or max) heap, i.e., that the value of each node is no greater than (or no less than) the values of its children"?

    Quote Originally Posted by RyanC
    In math if A->B then if A doesn't occur, all possibilities are accepted ! so here there's a root which doesn't have children, then we can say that root is min heap also there's a possibility to say it's not a min heap because the condition A doesn't occur, then all possibilities are accepted
    Actually, the more common way of expressing that min heap property is to say "the value of each node is no greater than (or equivalently, less than or equal to) the values of its children". So, if there are no children, then this is vacuously true, i.e., it is an example of how all the members of an empty set satisfy any property that can be ascribed to them: if there are no children, then it is vacuously true that the value of each node is greater than the values of its children.

    This means that a complete binary tree in which the root is a leaf is a min heap, it is also a max heap, it is also a binary search tree, and it is a balanced binary tree. Hence, whichever one we chose it to be depends on whichever one suits our purposes.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by laserlight View Post
    That does not describe a complete binary tree.


    That incompletely describes a max heap. I was hoping that you would list in detail both the properties of a min (or max) heap, and then in your next answer explain which one you were talking about and why.


    I asked "what is this property that you refer to?", not what are you confused about.


    I think you expressed this really poorly in posts #1 and #4. Instead of talking about "the leafs of binary complete tree is always satisfying the property of min/max heap" or even that "its trivial thats the leafs are satisfying minmum heap property", you should have asked: "why does a complete binary tree in which the root is a leaf trivially satisfy the other property of a min (or max) heap, i.e., that the value of each node is no greater than (or no less than) the values of its children"?


    Actually, the more common way of expressing that min heap property is to say "the value of each node is no greater than (or equivalently, less than or equal to) the values of its children". So, if there are no children, then this is vacuously true, i.e., it is an example of how all the members of an empty set satisfy any property that can be ascribed to them: if there are no children, then it is vacuously true that the value of each node is greater than the values of its children.

    This means that a complete binary tree in which the root is a leaf is a min heap, it is also a max heap, it is also a binary search tree, and it is a balanced binary tree. Hence, whichever one we chose it to be depends on whichever one suits our purposes.
    I got you but by definition of heap is : if there's children then the root is bigger/smaller that its children respectively to max/min heap.
    So now can we conclude that if there's no children then the claim(min/max heap) is trivial satisfying?!

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That's a wrong definition. You're only talking about the root, whereas the heap property talks about every node.

    Anyway, you already reasoned that out earlier. Yes, because given A->B, if A is false then any B could be true. That's the same underlying idea as the notion of vacuous truth. But it isn't good for your example to use "if there are children", because then instead of using vacuous truth, we could just add the clause "otherwise the heap property is satisfied".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. check if binary tree is complete
    By telmo_d in forum C Programming
    Replies: 0
    Last Post: 11-21-2015, 09:14 AM
  2. Replies: 2
    Last Post: 08-01-2007, 01:08 PM
  3. Finding the Root of a Complete Tree
    By Mr. Acclude in forum C++ Programming
    Replies: 5
    Last Post: 11-29-2005, 06:20 PM
  4. binary tree complete check
    By ichijoji in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2004, 05:48 PM
  5. display tree data in binary tree format
    By xddxogm3 in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2003, 12:47 AM

Tags for this Thread