Nws txhais li cas rau partition ib array?
Nws txhais li cas rau partition ib array?

Video: Nws txhais li cas rau partition ib array?

Video: Nws txhais li cas rau partition ib array?
Video: Tus Tswv Tab Tom Khob Qhov Rooj: Koj Puas Hnov Nws Lub Suab? (1) (Ntsiab Lus Tseem Ceeb) 2024, Kaum ib hlis
Anonim

Kev faib tawm nuj nqis hauv ib array . Koj muaj qhov loj, muaj peev xwm loj array ntawm cov khoom, nyob rau hauv ib tug randomorder. Koj xav cais cov array nyob rau hauv ob qhov chaw: lub qis ib nrab nrog cov khoom txuam nrog tus mob, lub sab sauv ib nrab ntawm cov khoom tsis txuam nrog tus mob. Txoj haujlwm no hu ua muab faib ntawm ib array.

Ntawm no, Quicksort muab faib ua array li cas?

Cov txheej txheem tseem ceeb hauv quickSort yog muab faib (). Lub hom phiaj ntawm muab faib yog, muab ib array thiab lub ntsiab lus x array raws li pivot, muab x atits txoj hauj lwm raug nyob rau hauv sorted array thiab muab tag nrho cov khoom me me (tsawg dua x) ua ntej x, thiab muab tag nrho cov ntsiab lus ntau dua (ntau dua x) tom qab x.

Qhov thib ob, Quicksort muab faib ua haujlwm li cas? Cov kev ceev algorithm yog ib tug sorting algorithm uas sorting ib sau los ntawm xaiv ib tug pivot point, thiab muab faib qhov sib sau nyob ib ncig ntawm lub pivot, yog li cov ntsiab lus me dua qhov pivot yog ua ntej nws, thiab cov ntsiab lus loj dua qhov pivot yog tom qab nws.

Tsis tas li ntawd, koj txhais li cas los ntawm qhov teeb meem partitioning?

Nyob rau hauv tus lej theory thiab computer science, lub teeb meem muab faib , los yog naj npawb muab faib , yog lub luag haujlwm ntawm kev txiav txim siab seb puas yog muab ntau qhov S ntawm cov lej zoo ua tau ua muab faib nyob rau hauv ob subsets S1 thiab S2xws li cov lej ntawm cov lej hauv S1 sib npaug ntawm cov lej hauv S2. Txawm tias cov teeb meem muab faib yog NP-

Dab tsi yog qhov ceev tshaj plaws sorting algorithm?

Lub sijhawm nyuaj ntawm Quicksort yog O (n log n) hauv qhov zoo tshaj plaws, O (nlog n) hauv qhov nruab nrab, thiab O (n ^ 2) hauv qhov phem tshaj. Tab sis vim tias nws muaj qhov ua tau zoo tshaj plaws hauv qhov nruab nrab rau feem ntau inputs, Quicksort feem ntau suav hais tias yog ceev tshaj plaws ” sorting algorithm.

Pom zoo: