SlideShare a Scribd company logo
1 of 15
COUNTING SORT
Design and Analysis of Algorithm
COUNTING SORT
 Step-1: Create a count array to store the count of
each unique object.
 Step-2: Modify count array by adding the previous
number.
 Step-3: Create output array by decrese count array.
Let the Array in range 0 to 5
1 4 3 2 3 5 2
Create an array that will hold the count of each number, with index
ranges from 0 to 5
Count
Input
0 1 2 2 1 1
[0] [1] [2] [3] [4] [5]
Modify count array by adding the previous number:
Input
1 4 3 2 3 5 2
Sum Count 0 1 3 5 6 7
[0] [1] [2] [3] [4] [5]
Output each object from the input sequence followed by
decreasing count by 1:
1 4 3 2 3 5 2
Input
Sum Count 0 1 3 5 6 7
[0] [1] [2] [3] [4] [5]
output
[1] [2] [3] [4] [5] [6] [7]
1 4 3 2 3 5 2
Input
Sum Count 0 1 3 5 1 1
[0] [1] [2] [3] [4] [5]
1output
Output each object from the input sequence followed by
decreasing count by 1:
[1] [2] [3] [4] [5] [6] [7]
1 4 3 2 3 5 2
Input
0 0 3 5 6 7
[0] [1] [2] [3] [4] [5]
1 4output
[1] [2] [3] [4] [5] [6] [7]
Sum Count
1 4 3 2 3 5 2
Input
0 0 3 5 5 7
[0] [1] [2] [3] [4] [5]
1 3 4output
[1] [2] [3] [4] [5] [6] [7]
Sum Count
1 4 3 2 3 5 2
Input
0 0 3 4 5 7
[0] [1] [2] [3] [4] [5]
1 2 3 4output
[1] [2] [3] [4] [5] [6] [7]
Sum Count
1 4 3 2 3 5 2
Input
0 0 2 4 5 7
[0] [1] [2] [3] [4] [5]
1 2 3 3 4output
[1] [2] [3] [4] [5] [6] [7]
Sum Count
1 4 3 2 3 5 2
Input
0 0 2 3 5 7
[0] [1] [2] [3] [4] [5]
1 2 3 3 4 5output
[1] [2] [3] [4] [5] [6] [7]
Sum Count
1 4 3 2 3 5 2
Input
0 0 2 3 5 6
[0] [1] [2] [3] [4] [5]
1 2 2 3 3 4 5output
[1] [2] [3] [4] [5] [6] [7]
Sum Count
1 4 3 2 3 5 2
Input
0 0 1 3 5 6
[0] [1] [2] [3] [4] [5]
1 2 2 3 3 4 5output
[1] [2] [3] [4] [5] [6] [7]
Sum Count
ARRAY IS NOW SORTED
TIME COMPLEXITY
for i<-1 to k do………………………..constant time
c[i]<- 0……………………………..constant time
for j<- 1 to n do…………………………………n time
c[A[j]]<- c[A[j]]+1……………………………………..n time
for i<-2 to k do……………………………………….constant time
c[i]<- c[i]+c[i-1]………………………………………..constant time
for j<- n down to 1 do…………………………………n
B[c[A[i]]]<- A[j]……………………………………………………..n
C[A[i]]<- C[A[j]] +1…………………………………………….n
T(n) =c+c+n+n+c+c+n+n+n
=5n+4c
Big(O)=n

More Related Content

What's hot

What's hot (20)

Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data Structure
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin Ramola
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Linked lists
Linked listsLinked lists
Linked lists
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Counting sort
Counting sortCounting sort
Counting sort
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Quick sort
Quick sortQuick sort
Quick sort
 
Hash table
Hash tableHash table
Hash table
 
Linked list
Linked listLinked list
Linked list
 

Similar to Counting Sort

Sorting of linked list data through python.ppt
Sorting of linked list data through python.pptSorting of linked list data through python.ppt
Sorting of linked list data through python.pptraahulraaz8
 
Algorithms lecture 3
Algorithms lecture 3Algorithms lecture 3
Algorithms lecture 3Mimi Haque
 
Quick sort and binary search PDF
Quick sort and binary search PDFQuick sort and binary search PDF
Quick sort and binary search PDFDivya modi
 
Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...
Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...
Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...mrhabib10
 
include ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfinclude ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfadisainternational
 
Searching.ppt
Searching.pptSearching.ppt
Searching.pptp83629918
 
11 1. multi-dimensional array eng
11 1. multi-dimensional array eng11 1. multi-dimensional array eng
11 1. multi-dimensional array eng웅식 전
 
CS-102 Data Structures HashFunction CS102.pdf
CS-102 Data Structures HashFunction CS102.pdfCS-102 Data Structures HashFunction CS102.pdf
CS-102 Data Structures HashFunction CS102.pdfssuser034ce1
 
第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)
第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)
第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)Wataru Shito
 

Similar to Counting Sort (20)

DSSchapt13.ppt
DSSchapt13.pptDSSchapt13.ppt
DSSchapt13.ppt
 
Algoritmo Counting sort
Algoritmo Counting sortAlgoritmo Counting sort
Algoritmo Counting sort
 
Hash table
Hash tableHash table
Hash table
 
AA_Sorting.SI.ppt
AA_Sorting.SI.pptAA_Sorting.SI.ppt
AA_Sorting.SI.ppt
 
Sorting of linked list data through python.ppt
Sorting of linked list data through python.pptSorting of linked list data through python.ppt
Sorting of linked list data through python.ppt
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Sorting
SortingSorting
Sorting
 
Review version 3
Review version 3Review version 3
Review version 3
 
Algorithms lecture 3
Algorithms lecture 3Algorithms lecture 3
Algorithms lecture 3
 
Quick sort and binary search PDF
Quick sort and binary search PDFQuick sort and binary search PDF
Quick sort and binary search PDF
 
Learn about algorithm
Learn about algorithm Learn about algorithm
Learn about algorithm
 
Searching.ppt
Searching.pptSearching.ppt
Searching.ppt
 
Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...
Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...
Searching Algorithms with Binary Search and Hashing Concept with Time and Spa...
 
include ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfinclude ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdf
 
Searching.ppt
Searching.pptSearching.ppt
Searching.ppt
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
11 1. multi-dimensional array eng
11 1. multi-dimensional array eng11 1. multi-dimensional array eng
11 1. multi-dimensional array eng
 
CS-102 Data Structures HashFunction CS102.pdf
CS-102 Data Structures HashFunction CS102.pdfCS-102 Data Structures HashFunction CS102.pdf
CS-102 Data Structures HashFunction CS102.pdf
 
第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)
第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)
第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)
 
q1
q1q1
q1
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

Counting Sort

  • 1. COUNTING SORT Design and Analysis of Algorithm
  • 2. COUNTING SORT  Step-1: Create a count array to store the count of each unique object.  Step-2: Modify count array by adding the previous number.  Step-3: Create output array by decrese count array.
  • 3. Let the Array in range 0 to 5 1 4 3 2 3 5 2 Create an array that will hold the count of each number, with index ranges from 0 to 5 Count Input 0 1 2 2 1 1 [0] [1] [2] [3] [4] [5]
  • 4. Modify count array by adding the previous number: Input 1 4 3 2 3 5 2 Sum Count 0 1 3 5 6 7 [0] [1] [2] [3] [4] [5]
  • 5. Output each object from the input sequence followed by decreasing count by 1: 1 4 3 2 3 5 2 Input Sum Count 0 1 3 5 6 7 [0] [1] [2] [3] [4] [5] output [1] [2] [3] [4] [5] [6] [7]
  • 6. 1 4 3 2 3 5 2 Input Sum Count 0 1 3 5 1 1 [0] [1] [2] [3] [4] [5] 1output Output each object from the input sequence followed by decreasing count by 1: [1] [2] [3] [4] [5] [6] [7]
  • 7. 1 4 3 2 3 5 2 Input 0 0 3 5 6 7 [0] [1] [2] [3] [4] [5] 1 4output [1] [2] [3] [4] [5] [6] [7] Sum Count
  • 8. 1 4 3 2 3 5 2 Input 0 0 3 5 5 7 [0] [1] [2] [3] [4] [5] 1 3 4output [1] [2] [3] [4] [5] [6] [7] Sum Count
  • 9. 1 4 3 2 3 5 2 Input 0 0 3 4 5 7 [0] [1] [2] [3] [4] [5] 1 2 3 4output [1] [2] [3] [4] [5] [6] [7] Sum Count
  • 10. 1 4 3 2 3 5 2 Input 0 0 2 4 5 7 [0] [1] [2] [3] [4] [5] 1 2 3 3 4output [1] [2] [3] [4] [5] [6] [7] Sum Count
  • 11. 1 4 3 2 3 5 2 Input 0 0 2 3 5 7 [0] [1] [2] [3] [4] [5] 1 2 3 3 4 5output [1] [2] [3] [4] [5] [6] [7] Sum Count
  • 12. 1 4 3 2 3 5 2 Input 0 0 2 3 5 6 [0] [1] [2] [3] [4] [5] 1 2 2 3 3 4 5output [1] [2] [3] [4] [5] [6] [7] Sum Count
  • 13. 1 4 3 2 3 5 2 Input 0 0 1 3 5 6 [0] [1] [2] [3] [4] [5] 1 2 2 3 3 4 5output [1] [2] [3] [4] [5] [6] [7] Sum Count
  • 14. ARRAY IS NOW SORTED
  • 15. TIME COMPLEXITY for i<-1 to k do………………………..constant time c[i]<- 0……………………………..constant time for j<- 1 to n do…………………………………n time c[A[j]]<- c[A[j]]+1……………………………………..n time for i<-2 to k do……………………………………….constant time c[i]<- c[i]+c[i-1]………………………………………..constant time for j<- n down to 1 do…………………………………n B[c[A[i]]]<- A[j]……………………………………………………..n C[A[i]]<- C[A[j]] +1…………………………………………….n T(n) =c+c+n+n+c+c+n+n+n =5n+4c Big(O)=n