Puas yog kev tshawb nrhiav linear zoo ib yam li kev tshawb fawb sib txuas?
Puas yog kev tshawb nrhiav linear zoo ib yam li kev tshawb fawb sib txuas?

Video: Puas yog kev tshawb nrhiav linear zoo ib yam li kev tshawb fawb sib txuas?

Video: Puas yog kev tshawb nrhiav linear zoo ib yam li kev tshawb fawb sib txuas?
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Hlis ntuj nqeg
Anonim

Chav Kawm: Nrhiav algorithm

Yog li ntawd, dab tsi yog qhov piv txwv ntawm kev tshawb nrhiav linear?

Kev Tshawb Fawb . Ib qho yooj yim tshaj plaws thiab theem pib tshawb nrhiav yog cov kev tshawb nrhiav , kuj hu ua a linear nrhiav . Raws li lub ntiaj teb tiag piv txwv , khaws phau ntawv xov tooj ze tshaj plaws thiab qhib rau thawj nplooj ntawv npe. Peb tab tom nrhiav nrhiav thawj "Smith".

Ib tug kuj yuav nug, dab tsi yog txhais los ntawm linear search? Kev tshawb nrhiav kab , kuj hu ua kev tshawb nrhiav , yog tus txheej txheem uas kuaj xyuas txhua lub ntsiab lus hauv daim ntawv teev npe ua ntu zus kom txog thaum pom cov khoom xav tau. Computational complexity rau linear nrhiav yog O(n), ua rau nws feem ntau tsawg npaum li cas binary nrhiav (O(log n)).

Ntawm no, qhov txawv ntawm linear search thiab binary search yog dab tsi?

A linear nrhiav scans ib yam khoom ntawm ib lub sij hawm, tsis txhob dhia mus rau ib yam khoom. Piv txwv li, binary nrhiav txiav koj nrhiav mus rau ib nrab kom sai li sai tau thaum koj pom qhov nruab nrab ntawm ib daim ntawv teev npe. Hauv linear nrhiav , qhov teeb meem nyuaj tshaj plaws yog O (n), qhov twg binary nrhiav ua O(log n) sib piv. Kev tshawb nrhiav kab siv ua ntu zus mus kom ze.

Dab tsi yog qhov nyuaj ntawm kev tshawb nrhiav linear?

Kev tshawb nrhiav kab

Chav kawm Nrhiav algorithm
Kev ua tau zoo tshaj plaws O(n)
Kev ua haujlwm zoo tshaj plaws O(1)
Nruab nrab kev ua tau zoo O(n)
Qhov phem tshaj qhov chaw complexity O(1) rov

Pom zoo: