SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
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

PPTX
Counting sort
PPTX
Quick Sort
PPTX
Merge sort and quick sort
PPTX
Quick sort
PPTX
Radix sort presentation
PPT
Counting Sort and Radix Sort Algorithms
PPT
Quick Sort
PDF
Sorting Algorithms
Counting sort
Quick Sort
Merge sort and quick sort
Quick sort
Radix sort presentation
Counting Sort and Radix Sort Algorithms
Quick Sort
Sorting Algorithms

What's hot (20)

PPTX
queue & its applications
PPTX
Priority Queue in Data Structure
PPTX
heap Sort Algorithm
PPT
Data Structure and Algorithms Binary Search Tree
PPTX
Data types in python
PPTX
Binary search
PPTX
linked list in data structure
PPTX
sorting and its types
PPTX
Queue - Data Structure - Notes
PPT
SEARCHING AND SORTING ALGORITHMS
PPTX
STACKS IN DATASTRUCTURE
PPTX
Merge sort algorithm
PPTX
PPTX
Binary Search Tree in Data Structure
PPTX
Python Exception Handling
PDF
Searching and Sorting Techniques in Data Structure
PDF
Java Linked List Tutorial | Edureka
PDF
sparse matrix in data structure
PPTX
Quicksort Presentation
PPTX
Insertion Sorting
queue & its applications
Priority Queue in Data Structure
heap Sort Algorithm
Data Structure and Algorithms Binary Search Tree
Data types in python
Binary search
linked list in data structure
sorting and its types
Queue - Data Structure - Notes
SEARCHING AND SORTING ALGORITHMS
STACKS IN DATASTRUCTURE
Merge sort algorithm
Binary Search Tree in Data Structure
Python Exception Handling
Searching and Sorting Techniques in Data Structure
Java Linked List Tutorial | Edureka
sparse matrix in data structure
Quicksort Presentation
Insertion Sorting
Ad

Similar to Counting Sort (20)

PPTX
Counting sort
PPTX
Counting sort
PPTX
Advance Algorithm_unit_2_czcbcnhgjy.pptx
PPT
Counting sort(Non Comparison Sort)
PPT
chapter-8.ppt
PDF
Sienna 8 countingsorts
PDF
06 Analysis of Algorithms: Sorting in Linear Time
PDF
DS & Algo 3 - Divide and Conquer
PPTX
Algorithms - Rocksolid Tour 2013
PDF
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
PPT
Introduction
PDF
Unit-1 DAA_Notes.pdf
PPTX
Sorting ppt
PPTX
Linear Sorting
PPT
Top school in delhi ncr
PPT
Algorithm Design and Analysis
PPTX
Radix sort
PPT
Cis435 week06
PDF
(1) collections algorithms
Counting sort
Counting sort
Advance Algorithm_unit_2_czcbcnhgjy.pptx
Counting sort(Non Comparison Sort)
chapter-8.ppt
Sienna 8 countingsorts
06 Analysis of Algorithms: Sorting in Linear Time
DS & Algo 3 - Divide and Conquer
Algorithms - Rocksolid Tour 2013
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
Introduction
Unit-1 DAA_Notes.pdf
Sorting ppt
Linear Sorting
Top school in delhi ncr
Algorithm Design and Analysis
Radix sort
Cis435 week06
(1) collections algorithms
Ad

Recently uploaded (20)

PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Introduction to Building Materials
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
1_English_Language_Set_2.pdf probationary
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
Empowerment Technology for Senior High School Guide
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
What if we spent less time fighting change, and more time building what’s rig...
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Hazard Identification & Risk Assessment .pdf
Introduction to Building Materials
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Indian roads congress 037 - 2012 Flexible pavement
LDMMIA Reiki Yoga Finals Review Spring Summer
Chinmaya Tiranga quiz Grand Finale.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
1_English_Language_Set_2.pdf probationary
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Computer Architecture Input Output Memory.pptx
Empowerment Technology for Senior High School Guide

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