Heap Data Structure:
Binary Heap: It is the binary tree representation of a given array.
3 conditions to build the heap:
1) root = Array[0]
2) left = Array[(2*i) + 1]
3) right = Array[(2*i) + 2]
Using these 3 rules we can obtain a binary heap
Binary Heap can be further changed to Max Heap or a Min Heap. This is useful when we want to use heap as a priority queue.
Max Heap Property: value(parent) is greater than value(child nodes)
Min Heap Property: value(parent) is less than value(child nodes)
In case of max heap root represents the maximum element of the whole tree which is true for all subtrees as well.
🔗Important Links:
Data Structures in Python: https://www.thinkxacademy.com/Data%20Structures%20in%20Python
🌐Join our community:
Android App(Notes+Videos): https://play.google.com/store/apps/details?id=com.thinkx.thinkx Facebook: https://www.facebook.com/thinkxacademy Twitter: https://www.twitter.com/thinkxacademy Instagram: https://www.instagram.com/thinkxacademy
#heap #datastructures #masterdsalgo #python