A heap is a ntoo-raws li ntaub ntawv qauv nyob rau hauv uas tag nrho cov nodes ntawm tsob ntoo yog nyob rau hauv ib tug meej kev txiav txim. Piv txwv li, yog tus niam txiv ntawm, ces tus nqi ntawm raws li ib qho kev txiav txim tshwj xeeb nrog rau tus nqi ntawm thiab tib qhov kev txiav txim yuav ua raws li cov ntoo.
Heap ntoo hauv cov ntaub ntawv yog dab tsi?
Definition: A heap is a specialized tree-based data structure uas txaus siab rau cov khoom heap: yog B yog tus me nyuam ntawm A, ces tus yuam sij (A) ≥ key(B). Qhov no txhais tau hais tias lub ntsiab lus nrog tus yuam sij loj tshaj plaws yog ib txwm nyob hauv lub hauv paus ntawm lub hauv paus, thiab yog li ntawd cov heap no qee zaum hu ua max-heap. Tau kawg, kuj tseem muaj min-heap.
pob zeb piav dab tsi?
Ib heap yog cov ntaub ntawv tsim los ntawm "nodes" uas muaj nuj nqis … Txawm hais tias txhua qhov ntawm ib lub pob yuav muaj ob lossis ntau dua cov menyuam yaus (tseem hu ua "cov menyuam yaus"), feem ntau cov pob txha txwv txhua qhov rau ob tus menyuam. Cov hom heap no tseem hu ua binary heaps thiab tej zaum yuav raug siv los khaws cov ntaub ntawv txheeb cais.
Dab tsi ua rau tsob ntoo binary ua heap?
A binary heap txhais tau tias yog tsob ntoo binary nrog ob qhov kev txwv ntxiv: … Heap khoom: tus yuam sij khaws cia hauv txhua lub ntawm yog ntau dua lossis sib npaug rau (≥) lossis tsawg dua lossis sib npaug. (≤) cov yuam sij hauv cov menyuam yaus, raws li qee qhov kev txiav txim tag nrho.
Yuav ua li cas cog tsob ntoo?
Kauj Ruam 1 - Tsim ib qho tshiab ntawm qhov kawg ntawm heap. Kauj Ruam 2 - Muab tus nqi tshiab rau ntawm node. Kauj Ruam 3 - Sib piv tus nqi ntawm tus me nyuam node nrog nws niam nws txiv. Kauj Ruam 4 - Yog tias tus nqi ntawm niam txiv tsawg dua tus menyuam, ces pauv lawv.