easy answer? on Heaps

closed account (NCRLwA7f)
Ok, so many places online that I am looking for help represent a heap as a pyramid binary tree looking visual representation.
so for example: 45,7,20,2,6,12,10
1
2
3
4
5
6
7

        45
     /       \
   7          20
 /   \        /  \  
2     6    12   10


is this just a visual representation, I have not read or heard anyone mention that heaps do not use pointers like a Binary Search Tree. Only my professor mentioned it in one of his videos, but it was very quick and he did point that out again later.

I understand the concept of representing the heap in an array where each "Parent's (n)" child is 2n(Left child) and 2n + 1 (right child).

1
2
3
 n =   1  2  3   4  5  6   7
     [45][7][20][2][6][12][10]


so my question is when building and sorting a heap, are where just working with the "heap array" or are we using some type of "tree" such as:

1
2
3
4
5
  struct Heap{
    int data;
    Heap* right;
    Heap* Left;
};


this has me very confused.
Last edited on
Drawing the heap as-if it was a binary tree helps illustrate the heap property. But that's just visual.

It is much simpler to use an array structure.
Last edited on
Topic archived. No new replies allowed.