Min Heap & Max Heap Tree's

can somebody explain how you build these trees from scratch and how to insert values? i remember that deletion always takes place at the root but not what happens afterwards. i don't need code just an explanation preferably with these numbers: 2,4,5,6,1,7,8,3,11
Bump
You need to mantain the heap property.

Deletion (max-heap): after you remove the root you check for the biggest children to occupy its place. Recurse.
Insertion: Put it at the end. if the heap property is broken, swap it with the father. Recurse.
Wikipedia doesn't really have a visual representation of building from scratch

Ne555 thanks but for insertion does the order of children matter? For min heap
Would it be

2
/ \
4. 5

?
Last edited on
does the order of children matter?
Nope, you just need to maintain the heap property. The son is bigger than the father, but you don't care about your brothers.
so if i were inserting these numbers in from left to right the tree would look like:

1
/ \
2 5
/ \ / \
3 4 7 8
/ \
6 11

?
Topic archived. No new replies allowed.