Qhov Sib txawv ntawm Kev Ncua Sort thiab Kev Xaiv Xaiv

Cov txheej txheem:

Qhov Sib txawv ntawm Kev Ncua Sort thiab Kev Xaiv Xaiv
Qhov Sib txawv ntawm Kev Ncua Sort thiab Kev Xaiv Xaiv

Video: Qhov Sib txawv ntawm Kev Ncua Sort thiab Kev Xaiv Xaiv

Video: Qhov Sib txawv ntawm Kev Ncua Sort thiab Kev Xaiv Xaiv
Video: Nkauj Ntseeg Tawm Tshiab 2022 | “Qhov Tseem Ceeb ntawm Kev Thov Vajtswv” 2024, Lub Xya hli ntuj
Anonim

Qhov Tseem Ceeb Qhov Sib Txawv - Ncua Sort vs Xaiv Xaiv

Kev txheeb xyuas thiab kev xaiv xaiv yog ob qhov kev txheeb xyuas cov txheej txheem siv los txheeb xyuas cov ntaub ntawv sau tseg. Qee lub sij hawm nws yog qhov tsim nyog los npaj cov ntaub ntawv hauv ib qho kev txiav txim tshwj xeeb. Sorting algorithms yog cov txheej txheem los txheeb xyuas cov ntaub ntawv. Nyob rau hauv sorting, cov ntaub ntawv yog teem raws li ib tug zauv los yog lexicographical txiav txim. Yog tias cov ntaub ntawv raug txheeb xyuas kom raug, ces nws yuav yooj yim rau kev tshawb nrhiav cov ntaub ntawv sai dua. Yog hais tias cov xov tooj nyob rau hauv ib tug xov tooj directory tsis nyob rau hauv ib tug sorted yam, ces nws yuav nyuaj nrhiav tau ib tug xov tooj tshwj xeeb. Ib yam li ntawd, yog tias cov lus hauv phau ntawv txhais lus tsis tau teem rau hauv cov ntawv sau, nws yuav nyuaj heev los nrhiav cov lus. Yog li ntawd, sorting yog pab tau nyob rau hauv lub neej txhua hnub. Hauv Computer Science, muaj sorting algorithms los txheeb xyuas cov ntaub ntawv. Ob lub algorithms no yog cov txheej txheem ntxig thiab xaiv xaiv. Qhov kev txheeb xyuas yog qhov kev txheeb xyuas cov txheej txheem uas txheeb cov array los ntawm kev hloov cov khoom ib los ntawm ib qho. Cov kev xaiv xaiv yog cov txheej txheem kev txheeb xyuas uas pom cov khoom me tshaj plaws hauv cov array thiab sib pauv cov khoom nrog thawj txoj haujlwm, tom qab ntawd nrhiav qhov thib ob qhov tsawg tshaj plaws thiab sib pauv nrog cov khoom nyob rau hauv txoj haujlwm thib ob thiab txuas ntxiv cov txheej txheem kom txog thaum tag nrho cov array raug txheeb xyuas.. Qhov sib txawv tseem ceeb ntawm cov txheej txheem ntxig thiab cov kev xaiv xaiv yog qhov kev ntxig ntxig sib piv ob lub ntsiab lus ntawm ib lub sijhawm thaum qhov kev xaiv xaiv xaiv qhov tsawg kawg nkaus ntawm tag nrho cov array thiab txheeb nws.

Dab tsi yog Insertion Sort?

Insertion sort is an in-place comparison-based sorting algorithm. Nyob rau hauv txoj kev no, cov array yog tshawb nrhiav ib kauj ruam. Cov khoom uas tsis tau txheeb xyuas tau txav mus thiab muab tso rau hauv cov npe sib cais ntawm cov array. Cov txheej txheem ntxig ntxig tuaj yeem piav qhia siv cov piv txwv hauv qab no.

Piv txwv li, coj thawj array li 77, 33, 44, 11, 88. Hauv qhov kev txheeb xyuas no, thawj kauj ruam yog xaiv lub caij tam sim no.

Lub caij tam sim no yog 77. Lub caij tam sim no muab piv nrog txhua lub ntsiab lus ntawm sab laug. 77, yog thawj lub ntsiab thiab tsis muaj cov ntsiab lus ntawm sab laug. Qhov ntsuas ntawm txoj haujlwm tam sim no yog 0.

Tom qab ntawd qhov ntsuas ntawm txoj haujlwm tam sim no yog nce ntxiv los ntawm 1. Tam sim no qhov ntsuas yog 1, thiab lub caij tam sim no yog 33. Thaum muab piv nrog lub caij nyob rau sab laug, nws yog me dua 77. Ces ob qho tib si cov nqi no. sib pauv. Tam sim no 33 yog nyob rau hauv index 0, thiab 77 yog nyob rau hauv index1.

Tam sim no cov array yog 33, 77, 44, 11, 88.

Dua ntxiv, qhov ntsuas tau nce ntxiv. Qhov ntsuas yog 2, thiab lub caij tam sim no yog 44. Nws yog piv nrog cov ntsiab lus nyob rau sab laug. 44 yog tsawg dua 77. Yog li ntawd ob qhov txiaj ntsig tau hloov pauv. Tam sim no cov array yog 33, 44, 77, 11, 88. Nws yog ib qho tsim nyog los sib piv tag nrho cov ntsiab lus ntawm sab laug. Yog li, 44 piv nrog 33. 33 me dua 44. Yog li cov ntsiab lus tsis tas yuav tsum tau pauv.

Tam sim no cov array yog 33, 44, 77, 11, 88.

Dua ntxiv, qhov ntsuas tau nce ntxiv. Qhov Performance index yog 3, thiab lub caij tam sim no yog 11. Nws yog piv nrog rau tag nrho cov ntsiab lus nyob rau sab laug. 11 yog tsawg dua 77, yog li ob qho no tau hloov pauv. Tam sim no lub array yog 33, 44, 11, 77, 88. Thaum muab piv 11 thiab 44, 11 yog tsawg dua 44. Yog li ntawd cov ob yog swapped. Tam sim no cov arrays yog 33, 11, 44, 77, 88. Dua 11 yog piv nrog 33. 11 tsawg dua 33, yog li ntawd ob qhov tseem ceeb yog swapped.

Tam sim no cov array yog 11, 33, 44, 77, 88.

Incrementing the index yuav ua rau index rau 4. Tus nqi yog 88. Nws yog siab tshaj 77. Yog li, tsis tas yuav muaj kev sib pauv. Thaum kawg, cov txheeb cais yog 11, 33, 44, 77, 88.

Qhov sib txawv ntawm Insertion Sort thiab Selection Sort
Qhov sib txawv ntawm Insertion Sort thiab Selection Sort

Daim duab 01: Insertion sort example

Kev siv ntawm qhov kev tso tawm yog raws li saum toj no. Thawj array yog 77, 33, 44, 11, 88. Tom qab sorting, nws muab cov zis 11, 33, 44, 77, 88.

Kev xaiv xaiv yog dab tsi?

Kev xaiv xaiv yog qhov sib piv hauv qhov chaw raws li kev txheeb xyuas cov txheej txheem. Cov arrays tau muab faib ua ntu. Qhov kev txheeb xyuas yog nyob rau sab laug kawg. Qhov tsis sib xws yog nyob rau ntawm txoj cai kawg. Ua ntej, qhov tsawg tshaj plaws tus nqi yuav tsum pom. Ces nws yog swapped nrog rau sab laug caij. Tam sim no lub ntsiab yog nyob rau hauv lub sorted array. Cov txheej txheem no txuas ntxiv mus rau qhov tsis sib xws array ciam teb ntawm ib lub caij mus rau sab xis. Cov kev xaiv xaiv algorithm tuaj yeem piav qhia siv cov piv txwv hauv qab no.

Piv txwv li, coj tus thawj array li 77, 33, 44, 11, 88, 22. Hauv qhov kev txheeb xyuas no, qhov tsawg tshaj plaws hauv cov array yog pom. Qhov tsawg tshaj plaws yog 11. Nws yog swapped nrog lub caij nyob rau hauv lub 0 Performance index ntawm array.

Tam sim no cov array yog 11, 33, 44, 77, 88, 22.

Qhov tsawg tshaj plaws yog nyob rau hauv qhov ntsuas 0, yog li 11 tam sim no tau txheeb. Los ntawm tag nrho cov ntsiab lus, qhov tsawg tshaj plaws yog 22. Nws yog swapped nrog 1st index element.

Tam sim no cov array yog 11, 22, 44, 77, 88, 33.

Lub ntsiab 11 thiab 22 twb tau txheeb. Los ntawm tus so, tus nqi tsawg tshaj plaws yog 33. Nws yog swapped nrog 2nd index element.

Tam sim no cov array yog 11, 22, 33, 77, 88, 44.

Cov ntsiab lus 11, 22 thiab 33 twb tau txheeb. Los ntawm tus so, tus nqi tsawg tshaj plaws yog 44. Nws yog swapped nrog 3rd index element.

Tam sim no cov array yog 11, 22, 33, 44, 88, 66.

Cov ntsiab lus 11, 22, 33, 44 twb tau txheeb. Cov ntsiab lus tseem ceeb yog 88 thiab 66. Lub caij 66 yog pauv nrog 4th index element.

Tam sim no cov array yog 11, 22, 33, 44, 66, 88.

Nws yog cov array array siv xaiv xaiv algorithm.

Qhov tseem ceeb sib txawv ntawm Insertion Sort thiab Selection Sort
Qhov tseem ceeb sib txawv ntawm Insertion Sort thiab Selection Sort

Daim duab 02: Kev xaiv Xaiv piv txwv

Kev siv ntawm qhov kev tso tawm yog raws li saum toj no. Thawj array yog 77, 33, 44, 11, 88. Tom qab sorting, nws muab cov zis 11, 33, 44, 77, 88.

Dab tsi yog qhov zoo sib xws ntawm Kev Tso Cai thiab Kev Xaiv Xaiv?

Ob qho Insertion Sort thiab Selection Sort yog sorting algorithms

Dab tsi yog qhov sib txawv ntawm Kev Ncua Sort thiab Kev Xaiv Xaiv?

Ntxhais Xaiv vs Xaiv Xaiv

Kev nkag nkag yog qhov kev txheeb xyuas cov txheej txheem uas txheeb cov array los ntawm kev hloov cov ntsiab lus ib los ntawm ib qho. Txoj kev xaiv yog kev txheeb xyuas cov txheej txheem uas pom cov khoom me tshaj plaws hauv cov array thiab sib pauv cov khoom nrog thawj txoj haujlwm, tom qab ntawd nrhiav qhov thib ob qhov tsawg tshaj plaws thiab sib pauv nrog cov khoom hauv txoj haujlwm thib ob thiab txuas ntxiv cov txheej txheem mus txog. tag nrho array yog txheeb.
txheej txheem
Kev nkag nkag yog txheeb xyuas cov npe sub los ntawm kev sib piv ob lub ntsiab kom txog rau tag nrho cov array raug txheeb. Kev xaiv xaiv xaiv qhov tsawg kawg nkaus thiab sib pauv nrog thawj txoj haujlwm, rov xaiv qhov tsawg kawg nkaus rau tus so thiab sib pauv nws yuav yog txoj haujlwm thib ob thiab txuas ntxiv cov txheej txheem no mus txog thaum kawg.
kev ruaj ntseg
Insertion sort is a ruaj khov sorting algorithm. Kev xaiv xaiv tsis yog qhov kev txheeb xyuas ruaj khov.

Summary – Insertion Sort vs Selection Sort

Qee zaum nws yog qhov tsim nyog los txheeb cov ntaub ntawv. Hauv Computer Science, muaj cov algorithms los txheeb cov ntaub ntawv. Kab lus no tau tham txog ob lub sorting algorithms uas yog kev nkag mus thiab kev xaiv xaiv. Qhov kev txheeb xyuas yog qhov kev txheeb xyuas cov txheej txheem uas txheeb cov array los ntawm kev hloov cov khoom ib los ntawm ib qho. Cov kev xaiv xaiv yog cov txheej txheem kev txheeb xyuas uas pom cov khoom me tshaj plaws hauv cov array thiab sib pauv cov khoom nrog thawj txoj haujlwm, tom qab ntawd nrhiav qhov thib ob qhov tsawg tshaj plaws thiab sib pauv nrog cov khoom nyob rau hauv txoj haujlwm thib ob thiab txuas ntxiv cov txheej txheem kom txog thaum tag nrho cov array raug txheeb xyuas.. Qhov sib txawv ntawm qhov kev nkag nkag thiab cov kev xaiv xaiv yog qhov kev sib cais sib piv ob lub ntsiab lus ntawm ib lub sijhawm thaum qhov kev xaiv xaiv xaiv qhov tsawg kawg nkaus ntawm tag nrho cov array thiab txheeb nws.

Download the PDF of Insertion Sort vs Xaiv Xaiv

Koj tuaj yeem rub tawm PDF version ntawm kab lus no thiab siv nws rau offline hom phiaj raws li daim ntawv ceeb toom. Thov rub tawm PDF version ntawm no: Qhov Sib txawv Ntawm Cov Ntawv Sau thiab Xaiv Xaiv

Pom zoo: