Thaum siv qhov kev sib cais?

Cov txheej txheem:

Thaum siv qhov kev sib cais?
Thaum siv qhov kev sib cais?

Video: Thaum siv qhov kev sib cais?

Video: Thaum siv qhov kev sib cais?
Video: Tswv Yexus lub neej thaum pib txug thaum xaus 2024, Hlis ntuj nqeg
Anonim

Usss: Insertion sort is siv thaum muaj pes tsawg lub ntsiab me me. Nws tseem tuaj yeem pab tau thaum cov tswv yim array yuav luag txheeb, tsuas yog ob peb lub ntsiab lus raug muab tso rau hauv kev ua tiav loj array.

Thaum twg kuv yuav tsum siv qhov kev sib cais?

Siv: Kev txheeb cais yog siv thaum tus lej ntawm cov khoom me me. Nws tseem tuaj yeem pab tau thaum cov tswv yim array yuav luag txheeb, tsuas yog ob peb lub ntsiab lus raug muab tso rau hauv kev ua tiav loj array.

Peb siv qhov kev nkag mus rau qhov twg?

Algorithm rau Insertion Sort

  1. Kauj Ruam 1 − Yog lub ntsiab yog thawj tus, nws twb tau txheeb.
  2. Kauj Ruam 2 - Txav mus rau lub ntsiab lus tom ntej.
  3. Kauj Ruam 3 - Sib piv cov khoom tam sim no nrog txhua lub ntsiab lus hauv cov array txheeb.
  4. Kauj Ruam 4 - Yog tias lub caij hauv qhov kev txheeb cais me dua li lub caij tam sim no, rov qab mus rau lub caij tom ntej.

Dab tsi yog qhov kev ntxig ntxig zoo tshaj plaws rau?

Insertion sort has a fast best-case run time and is a good sorting algorithm to use if the input list is twb feem ntau txheeb. Rau cov npe loj lossis ntau qhov tsis tau xaj, ib qho algorithm nrog lub sijhawm ua haujlwm nrawm dua thiab nruab nrab, xws li kev sib koom ua ke, yuav yog qhov kev xaiv zoo dua.

Dab tsi yog qhov txiaj ntsig tseem ceeb ntawm kev sib cais?

Kev sib cais muaj ntau qhov zoo suav nrog:

  • Tus ntshiab simplicity ntawm lub algorithm.
  • Tus txheeb ze ntawm cov khoom uas muaj cov yuam sij sib npaug tsis hloov.
  • Kev muaj peev xwm txheeb tau cov npe raws li tau txais.
  • Ua tau zoo rau cov ntaub ntawv me me, tshwj xeeb tshaj yog hauv kev xyaum dua li lwm cov quadratic algorithms - i.e. O(n²).

Pom zoo: