What two properties define a heap? → shape (complete tree) + heap-order (parent vs child).
Max-heap root is? → the maximum. Min-heap root? → the minimum.
Are siblings ordered? → No.
0-based children of i? → 2i+1,2i+2. Parent? → ⌊(i−1)/2⌋.
Height of n-node heap? → ⌊log2n⌋.
Why can't you search a heap in O(logn) like a BST? → only ancestor–descendant order, siblings unordered.
Recall Feynman: explain to a 12-year-old
Imagine a pyramid of people where every boss is taller than the people directly under them. The tallest person is always at the very top — you can see them instantly. But two people side-by-side might be any heights; we never compare them. When a new person joins, they stand at the next empty spot at the bottom, then keep swapping upward with their boss until they find someone taller above them. That swapping is short because the pyramid is wide and not very tall — so it's always quick.
Dekho, heap ek special binary tree hai jisme do rules hamesha lagte hain. Pehla shape rule: tree complete hona chahiye — har level pura bhara ho, sirf last level adhura ho sakta hai aur woh bhi left se right fill hota hai. Doosra order rule: max-heap me har parent apne children se bada ya barabar hota hai (sabse bada element top pe), aur min-heap me parent chhota ya barabar hota hai (sabse chhota top pe). Bas yahi ek local rule poore tree pe lagta hai.
Sabse important baat: heap me siblings ka koi order nahi hota. Bas ancestor aur descendant compare hote hain. Isiliye heap ko BST ki tarah O(log n) me search nahi kar sakte — heap sirf ek hi sawaal fast answer karta hai: "sabse bada/chhota kaun hai?" — woh root pe O(1) me mil jata hai.
Storage ka jugaad mast hai: kyunki tree complete hai, koi gap nahi hota, isliye hum pointers ki jagah simple array use karte hain. Index i ke children 2i+1 aur 2i+2 pe hote hain, parent ⌊(i−1)/2⌋ pe. Tree ki height hamesha ⌊log2n⌋ rehti hai, isliye insert (sift-up) aur delete (sift-down) dono O(logn) me ho jate hain — bas ek hi path top se bottom tak chalte hain.
Yeh cheez priority queue aur heapsort ke liye backbone hai. Jab bhi tumhe baar-baar "sabse urgent/sabse bada/sabse chhota nikalo" karna ho, heap best choice hai. Rule yaad rakho: max-heap me "Mom is the eXtreme" (parent bada), min-heap me "smallest swims up" (chhota upar).