Puas yog binary tshawb nrhiav sai tshaj plaws?
Puas yog binary tshawb nrhiav sai tshaj plaws?

Video: Puas yog binary tshawb nrhiav sai tshaj plaws?

Video: Puas yog binary tshawb nrhiav sai tshaj plaws?
Video: Peb Hmong 2 Tug Neeg Tshaj Lij Tshaj Plaws. 3/11/2021 2024, Kaum ib hlis
Anonim

Binary nrhiav yog sai dua tshaj li linear nrhiav tsuas yog rau cov array me me. Txawm li cas los xij, cov array yuav tsum tau txheeb ua ntej kom muaj peev xwm siv tau binary nrhiav . Muaj cov ntaub ntawv tshwj xeeb tsim los kom ceev ceev nrhiav , xws li cov rooj hash, uas tuaj yeem tshawb nrhiav tau zoo dua binary nrhiav.

Tsuas yog li ntawd, puas yog binary tshawb nrhiav sai dua li linear?

Binary nrhiav ua tau zoo dua tshaj li kev tshawb nrhiav linear ; Nws muaj lub sijhawm nyuaj ntawm O (log n). Daim ntawv teev cov ntaub ntawv yuav tsum nyob rau hauv ib qho kev txiav txim kom nws ua haujlwm. A binary nrhiav ua haujlwm los ntawm kev nrhiav qhov nruab nrab ntawm ib qho kev txheeb cais thiab muab piv rau koj lub hom phiaj.

Qhov thib ob, yog qhov kev tshawb nrhiav binary zoo tshaj plaws? Yog tias cov ntaub ntawv twb tau txheeb xyuas ntawm tus yuam sij koj nyob nrhiav rau, ces binary nrhiav nyob deb zoo dua tshaj linear nrhiav . Scaling rov qab me ntsis, yog tias muaj 40,000 cov ntsiab lus hauv array, binary nrhiav yuav raug nqi ntau tshaj 16 kev sib piv, thaum linear nrhiav yuav raug nqi ntau tshaj 40,000 kev sib piv thiab, qhov nruab nrab, 20,000 kev sib piv.

Hauv qhov no, qhov kev tshawb nrhiav ceev tshaj plaws yog dab tsi?

Nrhiav Binary

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

Binary nrhiav khiav hauv qhov phem tshaj logarithmic sij hawm , 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.

Pom zoo: