Qhov kev txheeb xyuas qhov twg yog qhov nrawm tshaj plaws?

Cov txheej txheem:

Qhov kev txheeb xyuas qhov twg yog qhov nrawm tshaj plaws?
Qhov kev txheeb xyuas qhov twg yog qhov nrawm tshaj plaws?
Anonim

Yog tias koj tau pom, lub sijhawm nyuaj ntawm Quicksort Quicksort Quicksort yog kev faib-thiab-tiav algorithm. Nws ua haujlwm los ntawm kev xaiv lub ntsiab lus 'piot' los ntawm array thiab muab faib rau lwm cov ntsiab lus rau hauv ob lub sub-arrays, raws li seb lawv tsawg dua lossis ntau dua li pivot. … Cov sub-arrays ces sorted recursively. https://en.wikipedia.org › wiki › Quicksort

Quicksort - Wikipedia

yog O(n logn) hauv qhov zoo tshaj plaws thiab qhov xwm txheej nruab nrab thiab O(n^2) hauv qhov phem tshaj plaws. Tab sis txij li nws muaj sab tes xis nyob rau hauv qhov nruab nrab qhov teeb meem rau feem ntau inputs, Quicksort feem ntau suav hais tias yog "ces" sorting algorithm.

Qhov twg yog qhov ceev tshaj plaws sorting algorithm xaj?

Lub sijhawm nyuaj ntawm Quicksort yog O (n log n) hauv qhov zoo tshaj plaws, O (n log 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 cov tswv yim, Quicksort feem ntau suav tias yog "ces" sorting algorithm.

Puas yog kev sib koom ua ke sai dua Quicksort?

Kev sib koom ua ke yog ntau dua thiab ua haujlwm nrawm dua li nrawm dua nyob rau hauv rooj plaub ntawm cov array loj lossis cov ntaub ntawv. Kev txheeb xyuas ceev yog qhov ua tau zoo dua thiab ua haujlwm sai dua li kev sib koom ua ke hauv cov ntaub ntawv me me lossis cov ntaub ntawv. sorting method: Txoj kev ceev ceev yog kev txheeb xyuas sab hauv qhov twg cov ntaub ntawv raug txheeb xyuas hauv lub cim xeeb loj.

Yuav ua li cas thiaj ua tau thiab nrawm?

Quicksort . Quicksort yog ib qho ntawm cov kev txheeb xyuas tau zoo tshaj plaws, thiab qhov no ua rau nws yog ib qho ntawm feem ntau siv thiab. Thawj qhov uas yuav tsum tau ua yog xaiv tus lej pivot, tus lej no yuav cais cov ntaub ntawv, ntawm nws sab laug yog cov lej me dua nws thiab cov lej ntau dua ntawm sab xis.

Yuav ua li cas cais cov tshuab nrawm dua?

Hauv kev xyaum, Quick Sort feem ntau yog qhov ceev tshaj plaws sorting algorithm. Nws qhov kev ua tau zoo yog ntsuas feem ntau hauv O (N × cav N). Qhov no txhais tau hais tias cov algorithm ua rau N × cav N sib piv los txheeb N ntsiab.

Pom zoo: