Puas heap xaiv xav tau chaw ntxiv?

Cov txheej txheem:

Puas heap xaiv xav tau chaw ntxiv?
Puas heap xaiv xav tau chaw ntxiv?

Video: Puas heap xaiv xav tau chaw ntxiv?

Video: Puas heap xaiv xav tau chaw ntxiv?
Video: Xav tau Txiv yau - Cualaim vaj 2024, Kaum ib hlis
Anonim

Heapsort yog kev sib piv-raws li kev txheeb xyuas algorithm uas siv cov ntaub ntawv binary heap. Zoo li mergesort mergesort Hauv computer science, kev sib koom ua ke (kuj feem ntau sau raws li kev sib koom ua ke) yog ib qho txiaj ntsig, lub hom phiaj dav dav, thiab kev sib piv-raws li sorting algorithm. Feem ntau cov kev siv tsim ib qho kev ruaj khov, uas txhais tau hais tias qhov kev txiav txim ntawm cov khoom sib npaug yog tib yam hauv cov tswv yim thiab cov khoom tawm. https://en.wikipedia.org › wiki › Merge_sort

Kev sib koom ua ke - Wikipedia

heapsort muaj lub sijhawm ua haujlwm ntawm O (n log ⁡ n), O (n\log n), O (nlogn), thiab zoo li kev sib cais, heapsort xaiv hauv qhov chaw, yog li tsis xav tau qhov chaw ntxiv thaum lub sijhawm xaiv.

Qhov chaw nco qhov xav tau ntawm heap yog dab tsi?

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 take O (1) O(1) O(1) space.

Vim li cas heap so O 1 qhov chaw nyuaj?

2 Teb. HEAP SORT siv MAX_HEAPIFY muaj nuj nqi uas hu nws tus kheej tab sis nws tuaj yeem ua tau siv qhov yooj yim thaum lub voj voog thiab yog li ua rau nws ua haujlwm rov qab uas tsis siv qhov chaw thiab vim li no Chaw Complexity ntawm HEAP SORT tuaj yeem txo musO(1).

Dab tsi yog qhov tseeb ntawm heap?

Heap sort is a kev sib piv-raws li kev txheeb xyuas raws li Binary Heap cov ntaub ntawv qauv. Nws zoo ib yam li kev xaiv xaiv qhov twg peb xub pom qhov tsawg kawg nkaus thiab tso qhov tsawg kawg nkaus ntawm qhov pib. Peb rov ua tib yam txheej txheem rau cov khoom seem.

Yuav ua li cas yog txoj hauj lwm ntawm 5 thaum lub max heap?

5 yuav yog at root.

Pom zoo: