Dab tsi yog qhov loj O ntawm kev tshawb nrhiav binary?
Dab tsi yog qhov loj O ntawm kev tshawb nrhiav binary?

Video: Dab tsi yog qhov loj O ntawm kev tshawb nrhiav binary?

Video: Dab tsi yog qhov loj O ntawm kev tshawb nrhiav binary?
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Hlis ntuj nqeg
Anonim

Binary nrhiav yog ceev tshaj linear nrhiav tsuas yog rau cov array me me.

Binary nrhiav algorithm.

Visualization ntawm lub binary nrhiav algorithm qhov twg 7 yog lub hom phiaj tus nqi
Chav kawm Nrhiav algorithm
Kev ua haujlwm zoo tshaj plaws O (1)
Nruab nrab kev ua tau zoo O (log n)
Qhov phem tshaj qhov chaw complexity O (1)

Ntawm no, dab tsi yog qhov nyuaj ntawm kev tshawb nrhiav binary?

Binary nrhiav khiav hauv lub sij hawm logarithmic phem tshaj plaws, ua O (log n) kev sib piv, qhov twg n yog tus naj npawb ntawm cov ntsiab lus hauv array, O yog Big O notation, thiab log yog logarithm. Binary nrhiav siv qhov chaw tsis tu ncua (O(1)), txhais tau hais tias qhov chaw coj los ntawm algorithm yog tib yam rau txhua tus lej ntawm cov ntsiab lus hauv array.

Tsis tas li ntawd, yog binary tshawb nrhiav ceev tshaj plaws? Yog thiab tsis yog. Yog muaj tshawb nrhiav uas yog ceev, nyob rau nruab nrab, tshaj ib tug bisection nrhiav . Tab sis kuv ntseeg tias lawv tseem yog O (lg N), tsuas yog nrog qis qis. Koj xav txo lub sijhawm los nrhiav koj lub caij.

Ib yam li ntawd ib tug yuav nug, ua li cas koj sau binary nrhiav?

Nrhiav Binary : Nrhiav ib tug txheeb array los ntawm rov faib cov nrhiav ntu ntu hauv ib nrab. Pib nrog ib ntus npog tag nrho cov array. Yog tus nqi ntawm cov nrhiav qhov tseem ceeb yog tsawg tshaj li qhov khoom nyob rau hauv nruab nrab ntawm lub caij nyoog, nqaim lub sij hawm mus rau lub qis ib nrab. Txwv tsis pub nqaim nws mus rau sab sauv ib nrab.

Lub sijhawm nyuaj ntawm kev tshawb nrhiav binary yog dab tsi?

Yog li yuav tsum muaj qee yam kev coj cwj pwm uas algorithm tau qhia kom muab ib nyuaj lub log n. Cia peb saib seb nws ua haujlwm li cas. Txij li thaum binary nrhiav muaj qhov ua tau zoo tshaj plaws ntawm O (1) thiab qhov xwm txheej phem tshaj plaws (qhov nruab nrab) kev ua haujlwm ntawm O (log n), peb yuav saib piv txwv ntawm qhov phem tshaj plaws. Xav txog ib qho array ntawm 16 yam.

Pom zoo: