2. Dab tsi yog qhov teeb meem nyuaj tshaj plaws hauv kev tsim lub heap? Kev piav qhia: Qhov teeb meem zoo tshaj plaws tshwm sim nyob rau hauv hauv qab-up kev tsimthaum peb muaj cov sortes array muab.
Dab tsi yog qhov teeb meem nyuaj tshaj plaws hauv kev tsim lub heap?
Tus naj npawb ntawm cov haujlwm yuav tsum tau nyob ntawm tus lej ntawm qib cov khoom tshiab yuav tsum nce siab kom txaus siab rau cov cuab yeej heap. Yog li, qhov kev ua haujlwm ntxig muaj lub sijhawm tsis zoo tshaj plaws ntawm O(log n).
Dab tsi yog qhov nyuaj ntawm heap?
Heap sort runs in O (n lg (n)) O(n\lg(n)) O(nlg(n)) lub sij hawm, uas scales zoo li n loj hlob. Tsis zoo li quicksort, tsis muaj qhov phem tshaj plaws O (n 2) O(n^2) O(n2) complexity. Qhov chaw zoo. Heap sort siv O (1) O (1) O (1) chaw.
Dab tsi yog qhov nyuaj ntawm heap?
Heapsort yog qhov ua tau zoo, tsis ruaj khov sorting algorithm nrog qhov nruab nrab, qhov zoo tshaj plaws, thiab lub sij hawm tsis zoo tshaj plaws ntawm O(n log n). Heapsort qeeb qeeb dua li Quicksort thiab Merge Sort, yog li Heapsort tsis tshua muaj tshwm sim hauv kev xyaum.
Lub sijhawm nyuaj ntawm kev tsim heap yog dab tsi?
Tsim ib qho array ntawm qhov loj 2n thiab luam cov ntsiab lus ntawm ob lub heaps rau qhov array no. Hu rau tsim heap rau array ntawm qhov loj 2n. Ua haujlwm heap siv sijhawm O(n) sijhawm. Ib txoj kab tseem ceeb tau ua raws li Max-Heap.