Cov txheej txheem:

Yuav ua li cas koj ua ib lub thoob ntaus ntawv?
Yuav ua li cas koj ua ib lub thoob ntaus ntawv?

Video: Yuav ua li cas koj ua ib lub thoob ntaus ntawv?

Video: Yuav ua li cas koj ua ib lub thoob ntaus ntawv?
Video: YUAV COJ LI CAS TU NEEG KOJ HLUB THIAJ NCO KOJ 2024, Kaum ib hlis
Anonim

Bucket sort ua haujlwm raws li hauv qab no:

  1. Teem ib array ntawm pib khoob " thoob ".
  2. Scatter: Mus hla tus thawj array, muab txhua yam khoom rau hauv nws thoob .
  3. Xaiv txhua yam uas tsis yog khoob thoob .
  4. Sau: Mus saib lub thoob nyob rau hauv kev txiav txim thiab muab tag nrho cov ntsiab lus rov qab rau hauv thawj array.

Ntxiv mus, dab tsi yog thoob sorted nrog piv txwv?

Tsis tas li, koj yuav pom kev ua haujlwm piv txwv ntawm thoob hom hauv C, C ++, Java thiab Python. Bucket Sort yog a kev xaiv txheej txheem ntawd hom cov ntsiab lus los ntawm thawj zaug faib cov ntsiab lus rau ntau pawg hu ua thoob . Cov ntsiab lus yog thawj zaug tawg mus rau hauv thoob ces cov ntsiab lus ntawm thoob yog txheeb.

Tsis tas li ntawd, qhov twg yog lub thoob ntim khoom siv? thoob hom Nws yog qhov tseem ceeb tshaj plaws thaum cov tswv yim sib faib sib faib ntau yam. Piv txwv li, xav txog cov teeb meem hauv qab no. Xaiv ib pawg loj ntawm ntab taw tes tus lej uas nyob hauv thaj tsam ntawm 0.0 txog 1.0 thiab tau muab faib ua ke thoob plaws qhov ntau.

Ua raws li qhov no hauv kev txiav txim siab, koj ua li cas thiaj nrhiav tau tus naj npawb ntawm cov thoob hauv ib lub thoob?

Yog thoob muaj qhov ntev 2^k, txhua thoob muaj size ib, thiab thoob hom degenerates rau hauv suav xaiv . Yog li, koj xav tau txhua thoob loj kom ntau tshaj 1. Yog tias peb muaj n thoob , thiab msbits(x, k) rov 2^k qhov tseem ceeb, ces txhua thoob qhov loj yog 2^k/n.

Lub sij hawm complexity ntawm thoob ntim yog dab tsi?

Qhov nruab nrab lub sij hawm complexity rau Bucket Sort yog O(n + k). Qhov phem tshaj lub sij hawm complexity yog O(n²). Qhov chaw nyuaj rau Thoob Sort yog O(n+k).

Pom zoo: