SlideShare a Scribd company logo
1 of 39
Gnome Sort
Hup university
20-02-2018
Gnome Sort
• The algorithm always finds the first place
where two adjacent elements are in the
wrong order, and swaps them. It takes
advantage of the fact that performing a swap
can introduce a new out-of-order adjacent
pair only next to the two swapped elements.
It does not assume that elements forward of
the current position are sorted, so it only
needs to check the position directly previous
to the swapped elements.
Algorithm
• procedure gnomeSort(a[]):
• pos := 0
• while pos < length(a):
• if (pos == 0 or a[pos] >= a[pos-1]):
• pos := pos + 1
• else:
• swap a[pos] and a[pos-1]
• pos := pos - 1
40<9? No , exchange then Backward
Is 40 < 9?
No
Swap (40,9)
No Backward
9<40? Yes, Forward
Is 9 < 40?
Yes
Go Forward
40<3? No, exchange Backward
Is 40 < 3?
No
Swap (40,3)
Go Backward
9< 3? No, exchange backward
Is 9 < 3?
No,
swap(9,3)
Go Backward
3<9? Yes, Forward
Is 3 <9?
Yes
Go Forward
9< 40? Yes, Forward
Is 9 < 40?
Yes
Go Forward
40<7? No, exchange Backward
Is 40 < 7?
No ,
swap(40,7)
Go Backward
9<7 ?No, exchange backward
Is 9 < 7?
No, swap(9,7)
Go Backward
3<7 ? Yes, Forward
Is 3 < 7?
Yes
Go Forward
7<9 ? Yes, Forward
Is 7 < 9?
Yes
Go Forward
9 <40? Yes, Forward
Is 9 < 40?
Yes
Go Forward
40<50? Yes, Forward
Is 40 < 50?
Yes
Go Forward
50< 23? No, exchange Backward
Is 50 < 23?
No
swap(50,23)
Go Backward
40<23? No, exchange Backward
Is 40 < 23?
No
Swap(40,23)
Go Backward
9<23? Yes, Forward
Is 9 < 23?
Yes
Go Forward
23>40? Yes, Forward
Is 23 < 40?
Yes
Go Forward
40<50? Yes, Forward
Is 40 < 50?
Yes
Go Forward
50<5?No, exchange Backward
Is 50 < 5?
No
Swap(50,5)
Go Backward
40<5?No, exchange Backward
Is 40 < 5?
No
Swap(40,5)
Go Backward
23<5?No, exchange Backward
Is 23 < 5?
No
Swap(23,5)
Go Backward
9<5? No, exchange Backward
Is 9 < 5?
Yes
Go Forward
7<5? No exchange Backward
Is 7 < 5?
No
Swap(7,5)
Go Backward
3<5? Yes , Forward
Is 3 < 5?
Yes
Go Forward
5<7? Yes, Forward
Is 5 < 7?
Yes
Go Forward
7<9? Yes, Forward
Is 7 < 9?
Yes
Go Forward
9<23? Yes, Forward
Is 9 < 23?
Yes
Go Forward
23<40? Yes, Forward
Is 23 < 40?
Yes
Go Forward
40<50?Yes, Forward
Is 40 < 50?
Yes
Go Forward
50<12? No, exchange Backward
Is 50 < 12?
No
Swap(50,12)
Go Backward
40<12? No, exchange Backward
Is 40 < 12?
No
Swap(40,12)
Go Backward
23<12? No, exchange Backward
Is 23 < 12?
No
Swap(23,12)
Go Backward
9<12? Yes, Forward
Is 9 < 12?
Yes
Go Forward
12<23? Yes, Forward
Is 12 < 23?
Yes
Go Forward
23<40? Yes Forward
Is 23 < 40?
Yes
Go Forward
40<50? Yes, Forward
Is 40 < 50?
Yes
Go Forward
End
At the end Rock
No check

More Related Content

What's hot (20)

Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
binary search tree
binary search treebinary search tree
binary search tree
 
Merge sort
Merge sortMerge sort
Merge sort
 
3.2 insertion sort
3.2 insertion sort3.2 insertion sort
3.2 insertion sort
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Insertion and merge sort
Insertion and merge sortInsertion and merge sort
Insertion and merge sort
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Insertion Sort
Insertion SortInsertion Sort
Insertion Sort
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
 
Shellshort ppt
Shellshort pptShellshort ppt
Shellshort ppt
 
Merge sort
Merge sortMerge sort
Merge sort
 
Linked stack-and-linked-queue
Linked stack-and-linked-queueLinked stack-and-linked-queue
Linked stack-and-linked-queue
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
Sorting
SortingSorting
Sorting
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 

More from zahraa F.Muhsen

More from zahraa F.Muhsen (20)

Compute skillspowerpoint lect2
Compute skillspowerpoint lect2Compute skillspowerpoint lect2
Compute skillspowerpoint lect2
 
Computer skills powerpoint intro
Computer skills powerpoint introComputer skills powerpoint intro
Computer skills powerpoint intro
 
Filter
FilterFilter
Filter
 
Table
TableTable
Table
 
List
ListList
List
 
Computer skills excel2010 5
Computer skills excel2010 5Computer skills excel2010 5
Computer skills excel2010 5
 
Computer skills excel2010 data
Computer skills excel2010 dataComputer skills excel2010 data
Computer skills excel2010 data
 
Computer skills excel2010 2
Computer skills excel2010 2Computer skills excel2010 2
Computer skills excel2010 2
 
Computer skills excel2010
Computer skills excel2010Computer skills excel2010
Computer skills excel2010
 
Computer skills excel2010 3
Computer skills excel2010 3Computer skills excel2010 3
Computer skills excel2010 3
 
Computer skills excel2010-4
Computer skills excel2010-4Computer skills excel2010-4
Computer skills excel2010-4
 
Computer skills excel2010
Computer skills excel2010Computer skills excel2010
Computer skills excel2010
 
Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithms
 
Internet search techniques
Internet search techniquesInternet search techniques
Internet search techniques
 
Nearest neighbor search
Nearest neighbor searchNearest neighbor search
Nearest neighbor search
 
Search methods
Search methodsSearch methods
Search methods
 
Hash function
Hash functionHash function
Hash function
 
Pigeonhole sort
Pigeonhole sortPigeonhole sort
Pigeonhole sort
 
Puzzle (1000 coins and 10 bags)
Puzzle (1000 coins and 10 bags)Puzzle (1000 coins and 10 bags)
Puzzle (1000 coins and 10 bags)
 
Php1
Php1Php1
Php1
 

Recently uploaded

RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024thyngster
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...ThinkInnovation
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 

Recently uploaded (20)

RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 

Gnome sort