Yuav ua li cas koj xam qhov complexity?
Yuav ua li cas koj xam qhov complexity?

Video: Yuav ua li cas koj xam qhov complexity?

Video: Yuav ua li cas koj xam qhov complexity?
Video: PRESTIN - Hnub No Koj Yuav Ncaim Mus (Cover) 2024, Kaum ib hlis
Anonim

Pab txhawb Qhov chaw : yog ib ntus qhov chaw (tsis suav cov tswv yim loj) faib los ntawm koj lub algorithm los daws qhov teeb meem, hais txog qhov loj me. Chaw complexity suav nrog ob tus pab qhov chaw thiab qhov chaw siv los ntawm kev nkag. Chaw complexity = Input Size + Auxiliary qhov chaw.

Ib yam li ntawd, qhov chaw complexity nrog piv txwv yog dab tsi?

Chaw complexity yog ib qho kev ntsuas ntawm tus nqi ntawm kev ua hauj lwm cia algorithm xav tau. Qhov ntawd txhais tau tias ntau npaum li cas nco, nyob rau hauv qhov phem tshaj plaws, yuav tsum tau nyob rau hauv txhua lub sij hawm nyob rau hauv lub algorithm. Raws li lub sijhawm nyuaj , peb feem ntau txhawj xeeb txog yuav ua li cas qhov chaw xav tau kev loj hlob, nyob rau hauv loj-Oh cov ntsiab lus, raws li qhov loj N ntawm cov tswv yim teeb meem loj hlob.

Tsis tas li ntawd, qhov algorithm twg muaj qhov chaw siab tshaj plaws? 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)

Tsis tas li ntawd, qhov chaw complexity thiab lub sij hawm complexity yog dab tsi?

Lub sijhawm nyuaj yog ib txoj haujlwm piav txog tus nqi ntawm sij hawm ib tug algorithm yuav siv sij hawm nyob rau hauv cov nqe lus ntawm tus nqi ntawm cov tswv yim rau lub algorithm. Chaw complexity yog ib txoj haujlwm piav qhia txog tus lej ntawm lub cim xeeb ( qhov chaw ) ib qho algorithm siv nyob rau hauv cov nqe lus ntawm tus nqi ntawm cov tswv yim rau lub algorithm.

Qhov chaw nyuaj puas suav nrog kev nkag?

Space complexity suav nrog ob leeg pab qhov chaw thiab qhov chaw siv los ntawm nkag.

Pom zoo: