Lub sijhawm zoo tshaj plaws ntawm kev sib koom ua ke yog dab tsi?
Lub sijhawm zoo tshaj plaws ntawm kev sib koom ua ke yog dab tsi?

Video: Lub sijhawm zoo tshaj plaws ntawm kev sib koom ua ke yog dab tsi?

Video: Lub sijhawm zoo tshaj plaws ntawm kev sib koom ua ke yog dab tsi?
Video: Daim phiaj saib sij hawm Zoo thiab Meej tshaj plaws 2024, Hlis ntuj nqeg
Anonim

Soj ntsuam algorithms

Algorithm Cov ntaub ntawv qauv Qhov chaw complexity: phem tshaj
Ceev ceev Array O(n)
Sib koom ua ke Array O(n)
Heap kev Array O(1)
Yooj yim Array O(1)

Ntxiv mus, dab tsi yog lub sij hawm complexity ntawm kev sib koom ua ke?

Cov complexity ntawm kev sib koom ua ke yog O (nlogn) thiab TSIS O (logn). Cov kauj ruam faib xam qhov nruab nrab ntawm txhua qhov sub-arrays. Txhua kauj ruam no tsuas yog siv O(1) sij hawm . Lub conquer kauj ruam recursively hom ob subarrays ntawm n/2 (rau txawm n) ntsiab txhua.

Dab tsi yog qhov zoo tshaj plaws lub sij hawm complexity ntawm npuas so? Qhov chaw nyuaj rau Npuas Sort yog O(1), vim hais tias tsuas yog ib qho chaw nco ntxiv yog xav tau xws li rau qhov hloov pauv temp. Tsis tas li ntawd, cov qhov zoo tshaj plaws lub sij hawm complexity yuav yog O(n), nws yog thaum lub npe twb lawm txheeb.

Tsis tas li ntawd, dab tsi yog qhov zoo tshaj plaws rooj plaub complexity ntawm kev sib koom ua ke?

n*log(n)

Dab tsi yog lub sij hawm khiav qhov nyuaj ntawm kev nkag mus rau hauv cov ntaub ntawv zoo tshaj plaws thiab cov xwm txheej phem tshaj plaws yog dab tsi?

Zoo tshaj , phem tshaj , thiab nruab nrab rooj plaub Cov qhov zoo tshaj plaws input yog ib qho array uas twb muaj lawm txheeb . Hauv no case insertion tsi muaj linear lub sijhawm ua haujlwm (ie, O(n)). Thaum lub sij hawm txhua iteration, thawj qhov seem ntawm cov tswv yim tsuas yog muab piv nrog rau txoj cai-feem ntau ntawm cov txheeb subsection ntawm lub array.

Pom zoo: