là tree có
min heap and max heap
min heap là root nhỏ nhất các node phải lớn hơn or bằng root
max heap là root lớn nhất các node phải nhỏ hơn or bằng root
theo chiều ngang thì các node ở tầng dưới phải cân bằng
bỏ index 0 start with 1
leftchild = (2*i)
rightchild = (2*i) +1
rootparent = i//2
Heap là một complete binary tree thỏa mãn heap property:
Heap không cần class node như BST — mà lưu bằng array (list).
Ta bỏ index 0, bắt đầu từ index 1 để dễ tính.
10
/ \\
15 20
/ \\ /
17 25 30
→ array biểu diễn:
[ _, 10, 15, 20, 17, 25, 30 ]
1 2 3 4 5 6