SlideShare a Scribd company logo
COMB SORTING
 The basic idea is to eliminate turtles, or small
values near the end of the list, Since in a
bubble sort these slow the sorting down
tremendously. Rabbits, large values around the
beginning of the list, do not pose a problem in
bubble sort.
 Instead of comparing adjacent elements, comb
sort allows for a larger gap between elements.
 This eliminates the number of required swaps.
 We get small numbers at the end to reach
beginning of the list.
 In bubble sort, when any two elements are
compared, they always have a gap (distance
from each other) of 1.
 The basic idea of comb sort is that the gap can
be much more than 1
 Rabbits & turtles: RABBITS are the elements
with the large values located near the
beginning while TURTLES are the elements
with the small values located near the end of
the list.
 Gap size the distance b/w two elements
 Shrink Factor usually taken 1.3
 Begin with a gap size equal to n
 Recalculate the gap size by dividing the
previous gap size by a shrink factor
 Iterate through the list, swapping elements
 If the gap is currently 1 and no swap is
occurred during this iteration, then the list is
sorted.
 Otherwise repeat.
Unsorted list
:
5 7 9 10 3 1 4 8 2 6
2 7 9 10 3 1 4 8 5 6
2 6 9 10 3 1 4 8 5 7
2 7 9 10 3 1 4 8 5 7
2 6 9 10 3 1 4 8 5 7
2 6 5 10 3 1 4 8 9 7
2 6 5 7 2 1 4 8 9 10
2 7 9 10 3 1 4 8 5 10
2 1 9 10 3 6 4 8 5 10
2 1 4 10 3 6 5 8 9 10
2 1 4 7 3 6 5 8 9 10
2 1 4 7 3 6 5 8 9 10
2 1 4 7 3 6 5 8 9 10
2 1 4 7 3 6 5 8 9 10
2 1 4 7 3 6 5 8 9 10
2 1 4 7 3 6 5 8 9 10
2 1 4 5 3 6 7 8 9 10
2 1 4 5 3 6 5 8 9 10
2 1 4 5 3 6 5 8 9 10
2 1 4 5 3 6 7 8 9 10
2 1 4 5 3 6 7 8 9 10
2 1 4 5 3 6 7 8 9 10
2 1 3 5 4 6 7 8 9 10
2 1 3 5 4 6 7 8 9 10
2 1 3 5 4 6 7 8 9 10
2 1 3 5 4 6 7 8 9 10
2 1 3 5 4 6 7 8 9 10
2 1 3 5 4 6 7 8 9 10
1 2 3 5 4 6 7 8 9 10
1 2 3 5 4 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
2 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
void combSort(int a[], int len)
{
int gap = len;
bool swapped;
do{
swapped = false;
gap = newGap(gap);
for(int i=0; i < len-gap; ++i){
if(a[i] > a[i+gap]){
swapped = true;
swap(a[i], a[i+gap]);
}
}
}while(gap > 1 || swapped);
for(int i=0;i<len;i++)
cout<<" "<<a[i];
}
 http://xlinux.nist.gov/dads/HTML/combSort.
html
 http://en.wikipedia.org/wiki/Comb_sort

More Related Content

What's hot

Comparison of pentium processor with 80386 and 80486
Comparison of pentium processor with  80386 and 80486Comparison of pentium processor with  80386 and 80486
Comparison of pentium processor with 80386 and 80486Tech_MX
 
Addressing mode
Addressing modeAddressing mode
Addressing modeilakkiya
 
8086 architecture
8086 architecture8086 architecture
8086 architecture
karthiga selvaraju
 
TEACHING PRESENTATION 1 - BASKETBALL .pptx
TEACHING PRESENTATION 1 - BASKETBALL .pptxTEACHING PRESENTATION 1 - BASKETBALL .pptx
TEACHING PRESENTATION 1 - BASKETBALL .pptx
Samboy Sambo
 
Divisibility rules
Divisibility rulesDivisibility rules
Divisibility rules
Kanhu Charan
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
maamir farooq
 
Linear Search
Linear SearchLinear Search
Linear Search
SWATHIR72
 
Binary search
Binary searchBinary search
Binary search
Gaurav Solanki
 
SAURABH MITRA-8086 MICROPROCESSOR
SAURABH MITRA-8086 MICROPROCESSORSAURABH MITRA-8086 MICROPROCESSOR
SAURABH MITRA-8086 MICROPROCESSOR
SAURABH MITRA
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
Jasleen Kaur (Chandigarh University)
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
chauhankapil
 
Memory banking-of-8086-final
Memory banking-of-8086-finalMemory banking-of-8086-final
Memory banking-of-8086-final
Estiak Khan
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)
Flynce Miguel
 
Memory segmentation-of-8086
Memory segmentation-of-8086Memory segmentation-of-8086
Memory segmentation-of-8086
mudulin
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
prabhakar jalasutram
 
4 different tennis grips
4 different tennis grips4 different tennis grips
4 different tennis grips
junhyungbaek
 
Protected mode memory addressing 8086
Protected mode memory addressing 8086Protected mode memory addressing 8086
Protected mode memory addressing 8086
University of Gujrat, Pakistan
 
address-translation-mechanism-of-80386 (1).ppt
address-translation-mechanism-of-80386 (1).pptaddress-translation-mechanism-of-80386 (1).ppt
address-translation-mechanism-of-80386 (1).ppt
1556AyeshaShaikh
 

What's hot (20)

Comparison of pentium processor with 80386 and 80486
Comparison of pentium processor with  80386 and 80486Comparison of pentium processor with  80386 and 80486
Comparison of pentium processor with 80386 and 80486
 
Addressing mode
Addressing modeAddressing mode
Addressing mode
 
8086 architecture
8086 architecture8086 architecture
8086 architecture
 
TEACHING PRESENTATION 1 - BASKETBALL .pptx
TEACHING PRESENTATION 1 - BASKETBALL .pptxTEACHING PRESENTATION 1 - BASKETBALL .pptx
TEACHING PRESENTATION 1 - BASKETBALL .pptx
 
Divisibility rules
Divisibility rulesDivisibility rules
Divisibility rules
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
 
Linear Search
Linear SearchLinear Search
Linear Search
 
Binary search
Binary searchBinary search
Binary search
 
SAURABH MITRA-8086 MICROPROCESSOR
SAURABH MITRA-8086 MICROPROCESSORSAURABH MITRA-8086 MICROPROCESSOR
SAURABH MITRA-8086 MICROPROCESSOR
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
 
Memory banking-of-8086-final
Memory banking-of-8086-finalMemory banking-of-8086-final
Memory banking-of-8086-final
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)
 
Memory segmentation-of-8086
Memory segmentation-of-8086Memory segmentation-of-8086
Memory segmentation-of-8086
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
4 different tennis grips
4 different tennis grips4 different tennis grips
4 different tennis grips
 
Protected mode memory addressing 8086
Protected mode memory addressing 8086Protected mode memory addressing 8086
Protected mode memory addressing 8086
 
address-translation-mechanism-of-80386 (1).ppt
address-translation-mechanism-of-80386 (1).pptaddress-translation-mechanism-of-80386 (1).ppt
address-translation-mechanism-of-80386 (1).ppt
 
Baseball
BaseballBaseball
Baseball
 

Viewers also liked

Shell sort
Shell sortShell sort
Shell sort
Rajendran
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
geeortiz
 
Акции лето 2014
Акции лето 2014Акции лето 2014
Акции лето 2014Liza Alypova
 
Vishvas resume template-2
Vishvas resume template-2Vishvas resume template-2
Vishvas resume template-2vishvasyadav45
 
Pmi pmp-resume template-14
Pmi pmp-resume template-14Pmi pmp-resume template-14
Pmi pmp-resume template-14vishvasyadav45
 
Cmmaao pmi-resume template-8
Cmmaao pmi-resume template-8Cmmaao pmi-resume template-8
Cmmaao pmi-resume template-8vishvasyadav45
 
Cmmaao roles-and-responsibilities-pmp-pmi
Cmmaao roles-and-responsibilities-pmp-pmiCmmaao roles-and-responsibilities-pmp-pmi
Cmmaao roles-and-responsibilities-pmp-pmivishvasyadav45
 
Intergenerational Commission slides - demographic trends and their impact on ...
Intergenerational Commission slides - demographic trends and their impact on ...Intergenerational Commission slides - demographic trends and their impact on ...
Intergenerational Commission slides - demographic trends and their impact on ...
ResolutionFoundation
 
Pmi pmbok-resume template-18
Pmi pmbok-resume template-18Pmi pmbok-resume template-18
Pmi pmbok-resume template-18vishvasyadav45
 
Cmmaao project-quality-metrics-pmi-pmp
Cmmaao project-quality-metrics-pmi-pmpCmmaao project-quality-metrics-pmi-pmp
Cmmaao project-quality-metrics-pmi-pmpvishvasyadav45
 
новая мастерская красоты tianDe
новая мастерская красоты tianDeновая мастерская красоты tianDe
новая мастерская красоты tianDeLiza Alypova
 
Observations to Information
Observations to InformationObservations to Information
Observations to Information
Simon Cox
 
Live and learn in Ireland presentation in Boston
Live and learn in Ireland presentation in BostonLive and learn in Ireland presentation in Boston
Live and learn in Ireland presentation in Boston
Tom Farrelly @TomFarrelly
 
RE/MAX AP - A Look back of 2013
RE/MAX AP - A Look back of 2013RE/MAX AP - A Look back of 2013
RE/MAX AP - A Look back of 2013
RE/MAX Andhra Pradesh
 
Алексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, Promodo
Алексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, PromodoАлексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, Promodo
Алексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, Promodo
Конференция Интернет-маркетинг в Украине
 
tugas akhir
tugas akhirtugas akhir
tugas akhirtoyoclub
 

Viewers also liked (20)

Shell sort
Shell sortShell sort
Shell sort
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 
Акции лето 2014
Акции лето 2014Акции лето 2014
Акции лето 2014
 
O realismo
O realismoO realismo
O realismo
 
Vishvas resume template-2
Vishvas resume template-2Vishvas resume template-2
Vishvas resume template-2
 
Pmi pmp-resume template-14
Pmi pmp-resume template-14Pmi pmp-resume template-14
Pmi pmp-resume template-14
 
Technisat
TechnisatTechnisat
Technisat
 
Cmmaao pmi-resume template-8
Cmmaao pmi-resume template-8Cmmaao pmi-resume template-8
Cmmaao pmi-resume template-8
 
Cmmaao roles-and-responsibilities-pmp-pmi
Cmmaao roles-and-responsibilities-pmp-pmiCmmaao roles-and-responsibilities-pmp-pmi
Cmmaao roles-and-responsibilities-pmp-pmi
 
Intergenerational Commission slides - demographic trends and their impact on ...
Intergenerational Commission slides - demographic trends and their impact on ...Intergenerational Commission slides - demographic trends and their impact on ...
Intergenerational Commission slides - demographic trends and their impact on ...
 
Pmi pmbok-resume template-18
Pmi pmbok-resume template-18Pmi pmbok-resume template-18
Pmi pmbok-resume template-18
 
Cmmaao project-quality-metrics-pmi-pmp
Cmmaao project-quality-metrics-pmi-pmpCmmaao project-quality-metrics-pmi-pmp
Cmmaao project-quality-metrics-pmi-pmp
 
новая мастерская красоты tianDe
новая мастерская красоты tianDeновая мастерская красоты tianDe
новая мастерская красоты tianDe
 
Observations to Information
Observations to InformationObservations to Information
Observations to Information
 
vitamin c
vitamin cvitamin c
vitamin c
 
2010 halloween
2010 halloween2010 halloween
2010 halloween
 
Live and learn in Ireland presentation in Boston
Live and learn in Ireland presentation in BostonLive and learn in Ireland presentation in Boston
Live and learn in Ireland presentation in Boston
 
RE/MAX AP - A Look back of 2013
RE/MAX AP - A Look back of 2013RE/MAX AP - A Look back of 2013
RE/MAX AP - A Look back of 2013
 
Алексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, Promodo
Алексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, PromodoАлексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, Promodo
Алексей Геращенко, Freud House; Евгений Сафонов, Владимир Медушивский, Promodo
 
tugas akhir
tugas akhirtugas akhir
tugas akhir
 

Similar to Aizaz comb sort

Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Edward Blurock
 
Sorting
SortingSorting
Sorting
Sameer Memon
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Zaid Hameed
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
m.kumarasamy college of engineering
 
Fraction Mass HOPE April 2013
Fraction Mass HOPE April 2013Fraction Mass HOPE April 2013
Fraction Mass HOPE April 2013rightstartmath
 
Times tables
Times tablesTimes tables
Times tables
teachingideas123
 
Ppt 1stelj Getallen
Ppt 1stelj GetallenPpt 1stelj Getallen
Ppt 1stelj Getallenguest18f0ed
 
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Muhammad Abuzar
 
Manipulacion de conjuntos
Manipulacion de conjuntosManipulacion de conjuntos
Manipulacion de conjuntos
Benjamín Joaquín Martínez
 
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdfSorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
ArjunSingh81957
 
cs1311lecture16wdl.ppt
cs1311lecture16wdl.pptcs1311lecture16wdl.ppt
cs1311lecture16wdl.ppt
RameshKumarYadav29
 
Bubble Sort Python
Bubble Sort PythonBubble Sort Python
Bubble Sort Python
ValneyFilho1
 
Bubble Sort.ppt
Bubble Sort.pptBubble Sort.ppt
Bubble Sort.ppt
MuhammadSheraz836877
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
Muhammad Hammad Waseem
 
Modul linus numerasi tahun 3
Modul linus numerasi tahun 3Modul linus numerasi tahun 3
Modul linus numerasi tahun 3
Habibah Yusoff
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for print
Abdii Rashid
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4ecomputernotes
 
Exact Real Arithmetic for Tcl
Exact Real Arithmetic for TclExact Real Arithmetic for Tcl
Exact Real Arithmetic for Tcl
ke9tv
 
one main advantage of bubble sort as compared to others
one main advantage of bubble sort as compared to othersone main advantage of bubble sort as compared to others
one main advantage of bubble sort as compared to others
Ajay Chimmani
 

Similar to Aizaz comb sort (20)

Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting
SortingSorting
Sorting
 
Sorting algos
Sorting algosSorting algos
Sorting algos
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
 
Fraction Mass HOPE April 2013
Fraction Mass HOPE April 2013Fraction Mass HOPE April 2013
Fraction Mass HOPE April 2013
 
Times tables
Times tablesTimes tables
Times tables
 
Ppt 1stelj Getallen
Ppt 1stelj GetallenPpt 1stelj Getallen
Ppt 1stelj Getallen
 
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
 
Manipulacion de conjuntos
Manipulacion de conjuntosManipulacion de conjuntos
Manipulacion de conjuntos
 
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdfSorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
 
cs1311lecture16wdl.ppt
cs1311lecture16wdl.pptcs1311lecture16wdl.ppt
cs1311lecture16wdl.ppt
 
Bubble Sort Python
Bubble Sort PythonBubble Sort Python
Bubble Sort Python
 
Bubble Sort.ppt
Bubble Sort.pptBubble Sort.ppt
Bubble Sort.ppt
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Modul linus numerasi tahun 3
Modul linus numerasi tahun 3Modul linus numerasi tahun 3
Modul linus numerasi tahun 3
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for print
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
Exact Real Arithmetic for Tcl
Exact Real Arithmetic for TclExact Real Arithmetic for Tcl
Exact Real Arithmetic for Tcl
 
one main advantage of bubble sort as compared to others
one main advantage of bubble sort as compared to othersone main advantage of bubble sort as compared to others
one main advantage of bubble sort as compared to others
 

Recently uploaded

Gujarat Details in Hindi for children's for presentation in school
Gujarat Details in Hindi for children's for presentation in schoolGujarat Details in Hindi for children's for presentation in school
Gujarat Details in Hindi for children's for presentation in school
shouryajoshi5
 
Unique Wedding Bands For Women Who Want To Stand Out.pptx
Unique Wedding Bands For Women Who Want To Stand Out.pptxUnique Wedding Bands For Women Who Want To Stand Out.pptx
Unique Wedding Bands For Women Who Want To Stand Out.pptx
Andrews Jewelers
 
30 Manipulation Techniques to be a smart person in society (1).pdf
30 Manipulation Techniques to be a smart person in society (1).pdf30 Manipulation Techniques to be a smart person in society (1).pdf
30 Manipulation Techniques to be a smart person in society (1).pdf
minaserver6679
 
From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...
From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...
From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...
Kitchen on Fire
 
What To Do If Your Ring Is Too Big? Must Read
What To Do If Your Ring Is Too Big? Must ReadWhat To Do If Your Ring Is Too Big? Must Read
What To Do If Your Ring Is Too Big? Must Read
Andrews Jewelers
 
What Makes Candle Making The Ultimate Bachelorette Celebration
What Makes Candle Making The Ultimate Bachelorette CelebrationWhat Makes Candle Making The Ultimate Bachelorette Celebration
What Makes Candle Making The Ultimate Bachelorette Celebration
Wick & Pour
 
Johnny Depp Long Hair: A Signature Look Through the Years
Johnny Depp Long Hair: A Signature Look Through the YearsJohnny Depp Long Hair: A Signature Look Through the Years
Johnny Depp Long Hair: A Signature Look Through the Years
greendigital
 
EXPERIENCE MONSTER BITES STREETWEAR APPAREL
EXPERIENCE MONSTER BITES STREETWEAR APPARELEXPERIENCE MONSTER BITES STREETWEAR APPAREL
EXPERIENCE MONSTER BITES STREETWEAR APPAREL
6ctbkfpdxz
 
erevna-influencers-social-media-stin-ellada
erevna-influencers-social-media-stin-elladaerevna-influencers-social-media-stin-ellada
erevna-influencers-social-media-stin-ellada
rvlassopoulou
 
La transidentité, un sujet qui fractionne les Français
La transidentité, un sujet qui fractionne les FrançaisLa transidentité, un sujet qui fractionne les Français
La transidentité, un sujet qui fractionne les Français
Ipsos France
 

Recently uploaded (10)

Gujarat Details in Hindi for children's for presentation in school
Gujarat Details in Hindi for children's for presentation in schoolGujarat Details in Hindi for children's for presentation in school
Gujarat Details in Hindi for children's for presentation in school
 
Unique Wedding Bands For Women Who Want To Stand Out.pptx
Unique Wedding Bands For Women Who Want To Stand Out.pptxUnique Wedding Bands For Women Who Want To Stand Out.pptx
Unique Wedding Bands For Women Who Want To Stand Out.pptx
 
30 Manipulation Techniques to be a smart person in society (1).pdf
30 Manipulation Techniques to be a smart person in society (1).pdf30 Manipulation Techniques to be a smart person in society (1).pdf
30 Manipulation Techniques to be a smart person in society (1).pdf
 
From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...
From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...
From Stress to Success How Oakland's Corporate Wellness Programs are Cultivat...
 
What To Do If Your Ring Is Too Big? Must Read
What To Do If Your Ring Is Too Big? Must ReadWhat To Do If Your Ring Is Too Big? Must Read
What To Do If Your Ring Is Too Big? Must Read
 
What Makes Candle Making The Ultimate Bachelorette Celebration
What Makes Candle Making The Ultimate Bachelorette CelebrationWhat Makes Candle Making The Ultimate Bachelorette Celebration
What Makes Candle Making The Ultimate Bachelorette Celebration
 
Johnny Depp Long Hair: A Signature Look Through the Years
Johnny Depp Long Hair: A Signature Look Through the YearsJohnny Depp Long Hair: A Signature Look Through the Years
Johnny Depp Long Hair: A Signature Look Through the Years
 
EXPERIENCE MONSTER BITES STREETWEAR APPAREL
EXPERIENCE MONSTER BITES STREETWEAR APPARELEXPERIENCE MONSTER BITES STREETWEAR APPAREL
EXPERIENCE MONSTER BITES STREETWEAR APPAREL
 
erevna-influencers-social-media-stin-ellada
erevna-influencers-social-media-stin-elladaerevna-influencers-social-media-stin-ellada
erevna-influencers-social-media-stin-ellada
 
La transidentité, un sujet qui fractionne les Français
La transidentité, un sujet qui fractionne les FrançaisLa transidentité, un sujet qui fractionne les Français
La transidentité, un sujet qui fractionne les Français
 

Aizaz comb sort

  • 2.  The basic idea is to eliminate turtles, or small values near the end of the list, Since in a bubble sort these slow the sorting down tremendously. Rabbits, large values around the beginning of the list, do not pose a problem in bubble sort.
  • 3.  Instead of comparing adjacent elements, comb sort allows for a larger gap between elements.  This eliminates the number of required swaps.  We get small numbers at the end to reach beginning of the list.  In bubble sort, when any two elements are compared, they always have a gap (distance from each other) of 1.  The basic idea of comb sort is that the gap can be much more than 1
  • 4.  Rabbits & turtles: RABBITS are the elements with the large values located near the beginning while TURTLES are the elements with the small values located near the end of the list.  Gap size the distance b/w two elements  Shrink Factor usually taken 1.3
  • 5.  Begin with a gap size equal to n  Recalculate the gap size by dividing the previous gap size by a shrink factor  Iterate through the list, swapping elements  If the gap is currently 1 and no swap is occurred during this iteration, then the list is sorted.  Otherwise repeat.
  • 6. Unsorted list : 5 7 9 10 3 1 4 8 2 6
  • 7. 2 7 9 10 3 1 4 8 5 6 2 6 9 10 3 1 4 8 5 7
  • 8. 2 7 9 10 3 1 4 8 5 7 2 6 9 10 3 1 4 8 5 7 2 6 5 10 3 1 4 8 9 7 2 6 5 7 2 1 4 8 9 10
  • 9. 2 7 9 10 3 1 4 8 5 10 2 1 9 10 3 6 4 8 5 10 2 1 4 10 3 6 5 8 9 10 2 1 4 7 3 6 5 8 9 10 2 1 4 7 3 6 5 8 9 10 2 1 4 7 3 6 5 8 9 10
  • 10. 2 1 4 7 3 6 5 8 9 10 2 1 4 7 3 6 5 8 9 10 2 1 4 7 3 6 5 8 9 10 2 1 4 5 3 6 7 8 9 10 2 1 4 5 3 6 5 8 9 10 2 1 4 5 3 6 5 8 9 10 2 1 4 5 3 6 7 8 9 10
  • 11. 2 1 4 5 3 6 7 8 9 10 2 1 4 5 3 6 7 8 9 10 2 1 3 5 4 6 7 8 9 10 2 1 3 5 4 6 7 8 9 10 2 1 3 5 4 6 7 8 9 10 2 1 3 5 4 6 7 8 9 10 2 1 3 5 4 6 7 8 9 10 2 1 3 5 4 6 7 8 9 10
  • 12. 1 2 3 5 4 6 7 8 9 10 1 2 3 5 4 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 2 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
  • 13. 1 2 3 4 5 6 7 8 9 10
  • 14. void combSort(int a[], int len) { int gap = len; bool swapped; do{ swapped = false; gap = newGap(gap); for(int i=0; i < len-gap; ++i){ if(a[i] > a[i+gap]){ swapped = true; swap(a[i], a[i+gap]); } } }while(gap > 1 || swapped); for(int i=0;i<len;i++) cout<<" "<<a[i]; }