Thread: Heaps of binary tree

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Heaps of binary tree

    Hi guys, I want to ask about heap.size which it means the number of elements that satisfying/following the property of heap(assuming its max heap), lets say I have an array of
    Code:
    {25,12,16,13,10,8,14}
    , then in this case we have a violation of the number 13 which is greater than its parent(12) so we say that the right subtree isn't satisfying the max heap property, as a result the heap.size is just 1 ((because there's just the number 25 which is satisfying that his value greater than its children)) ....I understand that but what about the left tree why we are not including it in the heap.size?! it's already following the property of max heap(16>8,16>14)

    thanks!

  2. #2
    Registered User
    Join Date
    Dec 2018
    Posts
    38
    I don't know if anyone else agrees, but it would be better to tell this guy that you won't answer any more strange disconnected questions. He should have to post a full program.

    I mean, you could of course tell him the obvious answer that the heap will contain 3 elements since 13 is the first one to break the heap property.

    But forcing him to write and ask questions about actual programs will mitigate the silliness somewhat.
    Last edited by bruteforce; 12-29-2018 at 11:14 AM.

  3. #3
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by bruteforce View Post
    I don't know if anyone else agrees, but it would be better to tell this guy that you won't answer any more strange disconnected questions. He should have to post a full program.

    I mean, you could of course tell him the obvious answer that the heap will contain 3 elements since 13 is the first one to break the heap property.

    But forcing him to write and ask questions about actual programs will mitigate the silliness somewhat.
    I know it breaks at 13 but why?! there's another right tree and its a heap!! but we we are not including it in the heap.size?! actually why at breakpoint we stop to modify the heap.size++?!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It sounds like bruteforce is right: why don't you write a program that uses a max-heap to do something useful? Then you can experiment with including whatever you want in the heap size, and see how that works or doesn't work.
    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. Converting From Binary Tree to Threaded Binary Trees
    By elton_fan in forum C Programming
    Replies: 15
    Last Post: 11-08-2007, 11:41 PM
  2. Replies: 2
    Last Post: 08-01-2007, 01:08 PM
  3. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  4. display tree data in binary tree format
    By xddxogm3 in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2003, 12:47 AM
  5. b-tree (not binary tree) implementation help
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 01-02-2002, 03:30 PM

Tags for this Thread