SlideShare a Scribd company logo
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

Heap sort
Heap sortHeap sort
Heap sort
Ayesha Tahir
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
DhanushSrinivasulu
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
irdginfo
 
BeyondClassicalSearch.ppt
BeyondClassicalSearch.pptBeyondClassicalSearch.ppt
BeyondClassicalSearch.ppt
jpradha86
 
Heap
HeapHeap
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
Merge sort
Merge sortMerge sort
Merge sort
Vidushi Pathak
 
Informed search
Informed searchInformed search
Informed search
Amit Kumar Rathi
 
Clustering: Large Databases in data mining
Clustering: Large Databases in data miningClustering: Large Databases in data mining
Clustering: Large Databases in data mining
ZHAO Sam
 
Lecture 14 splay tree
Lecture 14 splay treeLecture 14 splay tree
Lecture 14 splay tree
Abirami A
 
Floyd Warshall algorithm easy way to compute - Malinga
Floyd Warshall algorithm easy way to compute - MalingaFloyd Warshall algorithm easy way to compute - Malinga
Floyd Warshall algorithm easy way to compute - Malinga
Malinga Perera
 
PDA (pushdown automaton)
PDA (pushdown automaton)PDA (pushdown automaton)
PDA (pushdown automaton)
Захір Райхан
 
Fuzzy logic - Approximate reasoning
Fuzzy logic - Approximate reasoningFuzzy logic - Approximate reasoning
Fuzzy logic - Approximate reasoning
Dr. C.V. Suresh Babu
 
2 3 tree
2 3 tree2 3 tree
Quick sort
Quick sortQuick sort
Quick sort
Afaq Mansoor Khan
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
DrkhanchanaR
 
Graph algorithms
Graph algorithmsGraph algorithms
Graph algorithms
University of Haripur
 
Quicksort
QuicksortQuicksort
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
zzzubair
 
Intro to-iterative-deepening
Intro to-iterative-deepeningIntro to-iterative-deepening
Intro to-iterative-deepening
Adel Totott
 

What's hot (20)

Heap sort
Heap sortHeap sort
Heap sort
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
BeyondClassicalSearch.ppt
BeyondClassicalSearch.pptBeyondClassicalSearch.ppt
BeyondClassicalSearch.ppt
 
Heap
HeapHeap
Heap
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Merge sort
Merge sortMerge sort
Merge sort
 
Informed search
Informed searchInformed search
Informed search
 
Clustering: Large Databases in data mining
Clustering: Large Databases in data miningClustering: Large Databases in data mining
Clustering: Large Databases in data mining
 
Lecture 14 splay tree
Lecture 14 splay treeLecture 14 splay tree
Lecture 14 splay tree
 
Floyd Warshall algorithm easy way to compute - Malinga
Floyd Warshall algorithm easy way to compute - MalingaFloyd Warshall algorithm easy way to compute - Malinga
Floyd Warshall algorithm easy way to compute - Malinga
 
PDA (pushdown automaton)
PDA (pushdown automaton)PDA (pushdown automaton)
PDA (pushdown automaton)
 
Fuzzy logic - Approximate reasoning
Fuzzy logic - Approximate reasoningFuzzy logic - Approximate reasoning
Fuzzy logic - Approximate reasoning
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
Quick sort
Quick sortQuick sort
Quick sort
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
Graph algorithms
Graph algorithmsGraph algorithms
Graph algorithms
 
Quicksort
QuicksortQuicksort
Quicksort
 
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
 
Intro to-iterative-deepening
Intro to-iterative-deepeningIntro to-iterative-deepening
Intro to-iterative-deepening
 

More from zahraa F.Muhsen

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

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

一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Fernanda Palhano
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
74nqk8xf
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Kiwi Creative
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 

Recently uploaded (20)

一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 

Gnome sort