Count Sort

Count Sort is a one of the Fastest Sorting Algorithm. In Count Sort first We sort our array and find max element in our array. and now create a new array with the size of max element. Put the Number of cout of element of our array in new array of that element Index Number.


Count Sort Algorithm Implementation

                    

                        def shorting(count_data):
                        A=count_data
                        Result=[]
                    
                        for i in range(len(A)):
                            if A[i] == 1:
                                Result.append(i)
                            
                            elif A[i] > 1:
                                d=A[i]
                                while (d >= 1):
                                    Result.append(i)
                                    d-=1
                        
                        print("Sorted List is:",Result)
                    
                        def maxshort(arr):
                            Max=max(arr)+1
                            cout_data = [0]*Max
                    
                            for i in arr:
                                cout_data[i]+=1
                    
                            return cout_data
                    
                        a=[6,6,6,5,2,1,1,0,0,7,7]
                        b=maxshort(a)
                        shorting(b)
                        print("No Counted List is : ",maxshort(a))
                
                

Count Short Algorithm Analysis


                    Best Case: O(n+m)
                    Average Case: O(n+m)
                    Worst Case: O(n+m)
                    Space Complecity: O(n+m)
                    Count Short Algorithm are Internal Shorting Algorithm
                    Count Short Algorithm are Non Recursive Shorting Algorithm
                    Stability: No Count Short Algorithm Are Not Stable Algorithm
                    Adpative: No Count Short Algorithm Are Not Adpative Algorithm
                    Count Short Algorithm are take more much space
                   

© Written By Prince Singh