Dab tsi yog qhov nyuaj ntawm heap sort algorithm?
Dab tsi yog qhov nyuaj ntawm heap sort algorithm?

Video: Dab tsi yog qhov nyuaj ntawm heap sort algorithm?

Video: Dab tsi yog qhov nyuaj ntawm heap sort algorithm?
Video: Leng Yang - Yog Vim Dab Tsi (Official Full Song | Nkauj Tawm Tshiab) 2020/05/24 2024, Hlis ntuj nqeg
Anonim

Heap sort yog ib qho algorithm hauv qhov chaw. TimeComplexity : Lub sijhawm nyuaj ntawm heapify yog O (Logn). Lub sijhawm nyuaj ntawm createAndBuildHeap() yog O(n) thiab tag nrho lub sij hawm complexity Heap Sort yog O(nLogn).

Hais txog qhov no, qhov algorithm ntawm heap yog dab tsi?

Heap txheeb algorithm tau muab faib ua ob qhov hauv paus: Tsim ib Heap ntawm unsorted list/array. Ces a txheeb array yog tsim los ntawm kev rov tshem cov khoom loj tshaj plaws / tsawg tshaj plaws los ntawm pob , thiab ntxig nws mus rau hauv lub array. Cov pob yog reconstructed tom qab txhua tshem tawm.

Ib yam li ntawd, dab tsi yog lub sijhawm ua haujlwm ntawm heap sort algorithm? Txawm li cas los xij, quicksort muaj qhov phem tshaj plaws lub sijhawm khiav ntawm O (n 2) O (n ^ 2) O (n2) thiab qhov phem tshaj qhov chaw complexity ntawm O (log ? n O (log n O (logn), yog li ntawd tseem ceeb heev kom muaj qhov teeb meem ceev tshaj plaws) lub sijhawm khiav thiab siv tau qhov chaw zoo, heapsort yog qhov kev xaiv zoo tshaj plaws.

Ib yam li ntawd, nws tau nug, qhov nyuaj ntawm Heapify muaj nuj nqi yog dab tsi?

Lub tswv yim tseem ceeb yog nyob rau hauv build_heap algorithm qhov tseeb heapify tus nqi tsis yog O(log n) rau tag nrho cov ntsiab lus. Thaum heapify yog hu ua, lub sij hawm khiav yog nyob ntawm seb lub caij faran yuav txav mus rau hauv tsob ntoo ua ntej cov txheej txheem terminates. Lwm cov lus, nws nyob ntawm qhov siab ntawm lub caij hauv theheap.

Dab tsi sorting algorithm muaj qhov zoo tshaj plaws asymptotic complexity?

Rau Zoo tshaj Case Insertion Xaiv thiab Heap Xaiv yog qhov zoo tshaj plaws ib yam li lawv zoo tshaj plaws lub sijhawm ua haujlwm nyuaj yog O(n). Rau qhov nruab nrab zoo tshaj asymptotic khiav sijhawm nyuaj yog O(nlogn) uas muab los ntawm Merge Xaiv , Heap Xaiv , Ceev Xaiv . Rau qhov phem tshaj plaws zoo tshaj plaws khiav sijhawm nyuaj yog O(nlogn) uas muab los ntawm Merge Xaiv , Heap Xaiv.

Pom zoo: