Counting Sort:- Pros: -Time Complexity O(N) - Compareless sorting Cons: -Limited Usage i.e for int -Memory Consuption Uses: - Sort numbers - find counts of letter from string - remove duplicate from string - find kth smallest or biggest element from array within O(N) time. HAPPY LEARNING :)
@rajmhatre204 жыл бұрын
is your code working? if yes can you share the code here
@maulikshah284 жыл бұрын
@@rajmhatre20 Here you go brother: #include using namespace std; void countSort(int arr[], int n){ int k=arr[0]; for(int i=0; i arr[i]; } countSort(arr, n); // Printing for(int i=0; i
@celiafernandes90844 жыл бұрын
Thanks for enlightening
@johnwick-m4m3 жыл бұрын
@@maulikshah28 Your code doesn't work
@synergy_9442 жыл бұрын
@@maulikshah28 .
@maulikshah284 жыл бұрын
The people who come up with these ideas of sorting algorithms are true legends How can they think so far
Salute to the team🇮🇳! You all are really helping lots of students and has made education , fun to learn with easy explanation
@ayushgarg76093 жыл бұрын
ig, the size of count array could be k+1 and terminating condition of loop should also be (i
@chinmay_05182 ай бұрын
Variable size cannot be given to array, to use variable size some other concepts are required
@DawoodRizwan-k7f7 ай бұрын
You explaining so good...❤❤❤♥♥
@mohammadrafi8952 жыл бұрын
We can create a count array of size (k+1) instead of size 10.
@Ace-ex9gg10 ай бұрын
no
@mohammadrafi89510 ай бұрын
@@Ace-ex9gg Then explain the reason. Saying just 'no' doesn't contradict my statement.
@ankitwaghmare40074 жыл бұрын
The best things happen for students in 2020 is Aman bhaiya and his team come with this teaching facilities ....thank you bhaiya ..... Definately we will make you proud ...just wait ❤️❤️❤️❤️❤️❤️
@karanjaiswal46824 жыл бұрын
dynamic array can be allocated : int* count = new int [ k ];
@deveshdubey67763 жыл бұрын
Thanks bro
@deveshdubey67763 жыл бұрын
Why mam said we can't dynamically allocate memory to count array?
@karanjaiswal46823 жыл бұрын
@@deveshdubey6776 don't know why
@swostikpati75053 жыл бұрын
Why did ma'am assign the size of count array as 10. Won't it cause problems if the actual size is greater than 10?
@karanjaiswal46823 жыл бұрын
@@swostikpati7505 thats why I provided the code for dynamic array allocation
@anirudh37994 жыл бұрын
Bhai apni kaksha channel pe please biology daaalde yaar.Biology ke liye hee sab se zyada zarurat hai animation kaaaaa
@user-gt8ic3ti6l2 жыл бұрын
why we need to find the maximum element of an array while after we initialise the count array size 10.
@dhruvchokshi88052 жыл бұрын
it can be sorted in javascript by performing this: arr.sort(function(a,b){return a-b})...this will return the same output
@KumarSahil78 Жыл бұрын
This is normal sorting, in java and C++ also have these but the count sort is different.
@AliShair-f7q5 ай бұрын
If you create an array on the heap, such as with int* arr = new int[n]; --> the time complexity is O(n). If you create an array on the stack, such as with int arr[n]; --> the time complexity is O(1).
@uttamkarmakarece35343 жыл бұрын
Time complexity explained in only 2 minutes 😑...it should be explained in details But all over I love this playlist❤️
@parthapratimghose1733 жыл бұрын
The trick I did is create Madeleine plus 1 as size of counter array that will solve future memory overflow
@aniketmani75022 жыл бұрын
These sorting algorithms are really great. But still, you forgot about some legendary sorting techniques. 1. Bogo Sort 2. BogoBogo Sort 3. Miracle Sort 4. The Schrodinger's Sort
@divyam692 жыл бұрын
doo bee dooo beee dooo beee
@ChandanJobanputra2 жыл бұрын
Dont know why but my code is not giving any output Plz help
@rajiv-592 жыл бұрын
great work mam .............
@extremesatyaiitjeeair19803 жыл бұрын
// I think the final procedure (output array) is better in my idea void countSort(int a[],int n){ int k=a[0]; for(int i=1;i
@streetfood61834 жыл бұрын
Aman bhaiya... Unacademy plus IIT JEE subscription lene ke Baad kya... Hame class 11 Pura padhne k baad class 12 shuru hoga... Ya Phir dono parallel chalenge?
@marmikprajapati66813 жыл бұрын
What if there are negative numbers in array? We can't use count array in that case!!
@heyitsanmolj3 жыл бұрын
well, that's just not true. They have mentioned this before in some other video, you gotta use your brain tho. Make an array of length, -min(arr)+max(arr)+1 in case of negative numbers, and you can still do this!
@mayankbhardwaj34434 жыл бұрын
Hlo sir Web design/web development ke course kabb aayenge🙄🙄🙄 Plz upload fast...i want to learn that🙏❤️
@kartikarora35214 жыл бұрын
Bro if you want to learn it then I would recommend you to go to Mozilla Developer Network(aka MDN), it has open source content for learning web development/front-end development and it is made by Mozilla(The organisation that made Firefox Browser). And Bhiya will not upload web design because web design is related to graphic design it does not include coding. Front-end includes coding, which focus on coding the design and ui/ux made by a graphic designer. Web design and front-end are completely different
@mayankbhardwaj34434 жыл бұрын
@@kartikarora3521 thx for the information 😉❤️
@maulikshah284 жыл бұрын
If you really want to learn, then you can but Angela Yu 's Web Development course on udemy. It is really not a bad investment for about 450 rupees I am also learning from it. I highly recommend it
@mayankbhardwaj34434 жыл бұрын
@@maulikshah28 lol...why did u buy it😂😂....i downloaded it free ....😂😂😂want link?? Tell me 😂😂
@maulikshah284 жыл бұрын
@@mayankbhardwaj3443 really? How, tell me
@rishigupta96802 жыл бұрын
i have doubt ki jab ki agr jab extra output array lena hi hai to direct count wale array se kyun nhi sort kr skte index ko padkdo or uski value ko tab tak push kro jab tak wo zero na ho jaye
@harshwasnik76364 жыл бұрын
Ohho... Wo last me "byee".. Maje aa gye
@irannapatil70504 жыл бұрын
up to date i fallow this course and i feel and i know competitor of this course is not available on todays market.
@harsh4614 жыл бұрын
My Code School is still the best
@dheerajbisht40964 жыл бұрын
Then u haven't seen the market yet
@harsh4614 жыл бұрын
@@dheerajbisht4096 Bhai tu thapar sa ha kya?
@dheerajbisht40964 жыл бұрын
@@harsh461 no bro, ait pune
@irannapatil70504 жыл бұрын
@@dheerajbisht4096 tu hi bol bhai kaha pe hai isse accha
@mohitrathaur9670 Жыл бұрын
apka program nahi samagha pa rahe
@hustlewithVaibhav4 жыл бұрын
Thank you didi🙏
@himanshudawande3603 жыл бұрын
I would be very happy if the Apna college team could reply to us and solve our doubts because sometimes even searching a lot also doesn't solve the doubts . Or if possible please explain the things like why are you declaring this variable and why are you adding it etc in the video itself. THANK YOU the course is awesome
@ketangupta2213 жыл бұрын
I don't understand why we need to recursively add all the array elements for getting sum of elements till its previous elements. And then do that extra work of checking each number subtracting it and then putting it in array. We could have just taken elements from the count array which we had formed and just put those numbers in the array in ascending order according to their position in count array and their frequencies.
@lasbutious1163 жыл бұрын
I have the same doubt. why make something simple so complicated?
@riyanshkhandelwal3054 жыл бұрын
What if there is any negative element in an array? How we will store it in count array? And I also think that size of the count array is one greater than the maximum element in an array arr.
@maulikshah284 жыл бұрын
This code will not work if there are negative elements
@manishmalhotra58834 жыл бұрын
May use map then
@sourabhchoudhary72894 жыл бұрын
can we create count array of size k+1(k=max element in array) i.e. count[k+1]?
@harpic9494 жыл бұрын
Same doubt
@prince-kc6gq3 жыл бұрын
working for k+1 but dont know whether it is logically correct or not
@aakashthakre2443 жыл бұрын
Same doubt and also mam ne k kyu nhi liya 10 kyu liya wo reason bhi nhi samjha 😭
@sourabhchoudhary72893 жыл бұрын
@@aakashthakre244 I thik max+1 would work
@devjoshi70623 жыл бұрын
@@aakashthakre244 Array size + 1 is the way to go for this algorithm as it gives extra breathing space for us to store numbers
@snehilsinha46893 жыл бұрын
I think the size of the count array should be k+1 and not k. I even tried coding it out and it works for k+1 but not for k. Please confirm this once. 🙏
@suhasshenoy45413 жыл бұрын
yes because indicies start from 0 and kth index will be k+1 th element
@mayurschittaragi3 жыл бұрын
I had the exact same doubt and was confused for a long time.. Thanks for clearing.😊
@snehilsinha46893 жыл бұрын
@@mayurschittaragi pleasure helping 😊
@moonalexfeneba69443 жыл бұрын
I think you can also take n, As when we put the value of the max element in the array, but in our array, we have many repetitions For example in this question max element is 6 but the no. Of element is 9=n-1 so our loop will work fine if we use i
@simransaini90792 жыл бұрын
exactly you solved my problem
@mrwordpress66764 жыл бұрын
Thanku urvi goel ma'am
@chahitbhardwaj30752 жыл бұрын
Didi yeh batao ki yeh sabhi algorithm humko yaad rakhna hoga kya Thoda complex lag raha hai, agar yaad kare toh hum khud se algorithm kaise banayenge Pls reply...
@maccall01084 жыл бұрын
please cover the topic 2D array Dynamically
@aakashthakre2443 жыл бұрын
Ha yaar
@gaishiya76963 жыл бұрын
instead of allocating count array size as 10,we can use k+1 right ? actually that's why we are finding the max element .
@deveshdubey67763 жыл бұрын
Why mam said we can't dynamically allocate memory to count array?
@SaurabhKumar-ft3gt3 жыл бұрын
same question..
@devjoshi70623 жыл бұрын
idk why she did but looking for restricted memory prespective, you will surely get runtime error as it will reach past the maximum time allowed. Idk but still try, it can work also
@mitadey38764 ай бұрын
Can we skip the cumulative sum part and based on the index of count array add index of count array in original array.
@vrajeshmodi49283 жыл бұрын
There is one minor mistake in notes program ,You have to take 'k+1' as count array size. (Problem is in Line 6). Overall best course at KZbin for DSA loved it.
@faizanullah69223 жыл бұрын
thanks dude 🙂
@aaryan__bondekar97788 ай бұрын
yes, i had same doubt!
@nakulgite75654 жыл бұрын
Do we need to learn data-structure and Algorithm first to complete this course.. pls reply🙏
@sourabhchoudhary72894 жыл бұрын
This course will teach you DSA .
@maulikshah284 жыл бұрын
This course is of DSA, you don't need to learn anything before this
@piyushverma82073 жыл бұрын
How did she do that. She printed the array in main function. But for all we know that she only sent the values of arr in the function without referencing it.
@aakashthakre2443 жыл бұрын
She stored the value in original array in function in last lines
@piyushverma82073 жыл бұрын
@@aakashthakre244 You got that wrong. She could access the array from a function because arr is a pointer. If you try to do the same thing with an int variable, you will not be able to do that
@shivanshpratap36243 жыл бұрын
@@piyushverma8207 GCC Compilers takes array in functions as a reference by default
@akashayanand7 ай бұрын
why is there overhead of creating a 'position array' our goal can be achieved from the count array itself. this code is not optimal?
@nishantgarg28153 жыл бұрын
can't you simply use count array to put numbers in new array since you know frequency of each number.Something like int k=0; for(int i=0;i0){ for(int j=0;j
@lasbutious1163 жыл бұрын
I have the same exact question. will it not be a lot easier to create the new array because we already know the frequency of each element?
@iamkanishkyadav3 жыл бұрын
Because then Time complexity will become Big-O of N^2 ie O(n^2) . But we want optimal O(n).
@nishantgarg28153 жыл бұрын
@@iamkanishkyadav Its O(N) not O(N^2).Check again
@iamkanishkyadav3 жыл бұрын
@@nishantgarg2815 I am stuck, right now, but ur code is not simple O(n), may be something else. May be I need to go more depth in time complexity.
@lasbutious1163 жыл бұрын
what if the range of data is big? suppose array=[100000,1,80] then except for these 3 values all 100000 variables will have count 0 but still we have to traverse through all of them
@deepakmodi93432 жыл бұрын
Nice explanation and a nice video.
@harshwasnik76364 жыл бұрын
Di will it work for negative values? Coz u can't store no. of times that element occurred. Please do correct me if I am wrong.
@thesomebody54394 жыл бұрын
I guess we just have to mod the values
@hunterzolomon68423 жыл бұрын
@@thesomebody5439 ni be lolu
@deveshdubey67763 жыл бұрын
counting sort is incapable of sorting negative numbers...but there is a modified counting sort which can do it
@abhijeetgautam5873 жыл бұрын
Find the minimum element of the array. Then declare an integer: int convert_factor = (0 - minElement); Now add convert_factor to every element of the original array. Then use the usual QuickSort algorithm and obtain the sorted array. Finally, before printing the sorted array, subtract convert_factor from each element of the sorted array.
@leo-x1d1f3 жыл бұрын
in notes please correct count array size is max+1 that means k+1 but in note take only k which is wrong
@shubhamkale7353 жыл бұрын
When yoou are at another level of coding ......... Thank you aman sir and team ... l
@adityamishra82962 жыл бұрын
maine same code likha tha not working😥😥
@NitishYadav-rb9ki4 жыл бұрын
Web development ka course kab aayega
@fardinalam72902 жыл бұрын
how could be time complexity is O(N)??? when she used first loop as a traverse whole array after that used 2,3 loops?
@sumitkevlani57403 жыл бұрын
Hamne maximum Element nikalkar ke us length +1 ki array bnayi but suppose agar array me negative number aaya tab to yeh algorithm kaam nhi aayega
@gauravjha42094 жыл бұрын
Bro plz help me how to improve Maths my maths subject is week but i hope u make a one video for us
@ashwinshetgaonkar63293 жыл бұрын
we can allocate memory for dynamically for array,
@abhisheknishad24014 жыл бұрын
Awsm mam
@makarandpundlik10833 жыл бұрын
Can we sort -ve elements using this method ?
@AkshitPanday3 жыл бұрын
No this can be applied only on array with non-negative elements as frequencies cannot take -ve indexes
@abhijeetgautam5873 жыл бұрын
Find the minimum element of the array. Then declare an integer: int convert_factor = (0 - minElement); Now add convert_factor to every element of the original array. Then use the usual QuickSort algorithm and obtain the sorted array. Finally, before printing the sorted array, subtract convert_factor from each element of the sorted array.
@makarandpundlik10833 жыл бұрын
@@abhijeetgautam587 great, that will work.
@jiosim13773 жыл бұрын
Isnt the time complexity of count sort O(n+k)?? Can someone explain please??
@sawanpatel34913 жыл бұрын
it's O(n)+O(k); but we are performing on large number of elements i.e. 10^7. so we ignore it.
@vinaywalia87234 жыл бұрын
there so many for loops so that can increase the time complixicity just asking
@sourabhchoudhary72894 жыл бұрын
Actually O(n)+O(n) is approximately equal to O(n)!
@rambabupatidar30923 жыл бұрын
how No of element in count array are coming from max element of arr array . For eg . If arr is 6,8,12,3,4,5,2,6 In this case k will come out to be 12 but acutually k must be 7 as there are only 7 distinct element in array.
@walwinvirlar68734 жыл бұрын
I did not understand when she said we can't make dynamic array then 5 lines later makes a dynamic array of size n could someone explain to me how?
@aakashthakre2443 жыл бұрын
Same ques
@harendraseervi55253 жыл бұрын
#include using namespace std; int main() { vectorv; int arr[]={1,5,3,1,2,3,4,4,2}; int maxno=-55; for(int i=0;i
@minimaxhindi Жыл бұрын
Please create a video on bucket sort
@aaryansaha96163 жыл бұрын
Can someone clear it ? How does count[ arr [ i] ] ++ ; work ?
@snehilsinha46893 жыл бұрын
basically, you are using the technique here called hashing in which you are making a new array to store the count of every element of the original array. This works in the following way -> 1. You are using the index number of the new array to represent the value of your array element i.e. arr[i] 2. Then you are incrementing on that index each time your element occurs in the array by doing count[j]++ where j=arr[i] works as the index. 3. Thus in this way the new array stores the count of each element of the array and its index helps identify the corresponding elements which will be useful while accessing it. Hope it helps 🙏
@monikaraut52662 жыл бұрын
Here count is basically Array of counts, in which you are storing count of elements, you will store count of 0 at index 0, count of 1 at index 1 , count of 2 at index 2 and so on.. e.g. When you see 2, you will increment value at index 2 in count array
@nageshwarmitkar27084 жыл бұрын
Bhaiya please suggest best videos for digital marketing.
@pritishpattnaik46744 жыл бұрын
can we do this by combination of vectors and pairs ?
@shubhamhelloworld3213 жыл бұрын
Yessssss
@aakashthakre2443 жыл бұрын
Many doubts no solution on net also please tell us where to ask doubt so teachers can reply
@gandhijainamgunvantkumar67832 жыл бұрын
Amazing explanation :)
@sahilbheke40832 жыл бұрын
6:56 why can't we take k as a size
@aaruljuneja48754 жыл бұрын
Please🙏🙏🙏🙏 also make video on python language
@anuragpandey33413 жыл бұрын
FAANG Motivation video: 1day - 1million views Actual knowledge to crack FAANG companies: 1year - 50k views What's the use of motivation without hardwork?
@ishangupta92943 жыл бұрын
totally agreed! everybody wants to work in FAANG but dont want to work upon what it takes to get there
@faizanahmed9304 Жыл бұрын
What for negative numbers?
@gauravdhiran94743 жыл бұрын
Code is not printing any output , can you please give me the solution what can I do to get the output
@rudrakalyan4567 Жыл бұрын
Thank you mam
@saswatsamal11993 жыл бұрын
why can the array be dynamically allocated at - 6:57
@sahilgupta71703 жыл бұрын
make array of size k+1 it will work
@bestluckstar29673 жыл бұрын
How can we apply the counting sort algorithm to sort array with negative numbers?
@shailendramaheshwari54713 жыл бұрын
by taking the abs() value of the negative elements in an array
@saisriangajala83992 жыл бұрын
Why do we iterate from back why can't from front??
@depressinglyfunny3 жыл бұрын
i have a doubt? why cant we make a dynamic array in the count sort function??
@siddharth40693 жыл бұрын
Counting sort only works when the range of potential items in the input is known ahead of time. If the range of potential values is big, then counting sort requires a lot of space
@avinashgupta23082 жыл бұрын
int count[K+1] --> why not this ? but count[10] this ?
@vijaysbuddhi5252 Жыл бұрын
Guys how much time did it took for U complete this lec? Just asking
@aritraganguly39572 жыл бұрын
does count sort come in interview
@aakanshasoy3921 Жыл бұрын
Last element me Garbage value show hora hai use kese solve kru ?
@sit33darshanpagar163 жыл бұрын
3:51 why we are decrementing and then storing value in array. 😔
@its_neel_ok3 жыл бұрын
cause we added the values to get the position. So, if we want the position in sorted order we have to go reverse(from end to start), we can' t do that from start to end
@md.ualiurrahmanrahat24003 жыл бұрын
there is a problem with the code. when the original array size is less than the max element of the array, then the program crashes. For, ex;: arr[] = {18,1,8,1,20} here n = 5, but k = 20; so, array can't take elements if you can't handle correctly the size of the array inside the function. Wish much focus was given in the concept explanation than animation of the video
@shivanshpratap36243 жыл бұрын
Why so?
@Abhishek-zx5zz Жыл бұрын
Negative elements ma frequency kesa count kar payga
@satyamsingh33 жыл бұрын
Bouncer bhai sahab
@angadchoudhary27733 жыл бұрын
Can anyone explain the word at 6:57 ?
@pratham99544 жыл бұрын
Why he is providing course for free even there are no ads in all course??
@AdityaKumar-pp4xw4 жыл бұрын
He has multiple channels too, Long term investment I guess
@mohammadanas79294 жыл бұрын
Thku mam❤️❤️
@sachinkashi Жыл бұрын
What if there are negative numbers also included to be sorted
@mbasimirfan5465 Жыл бұрын
ye hi to masla aa raha
@Yahy_Sani2 жыл бұрын
#include using namespace std; int main() { int n; cin >> n; int a[n]; int N = 0; for (int i = 0; i < n; i++) { cin >> a[i]; N = N < a[i] ? a[i] : N; } int countArr[N + 1] = {0}; for (int i = 0; i < n; i++) { countArr[a[i]]++; } int k=0; for (int i = 0; i < N+1; i++) { for (int j = countArr[i]; 0
@ayushmishra139610 ай бұрын
What if the value of element of array is -1
@rohanupahyay37914 жыл бұрын
Notes??
@shreyasingh46802 жыл бұрын
what if the array contains negative elements?
@higgsboson3882 Жыл бұрын
then you would have to find the minmum element and make array accordingly for eg -3 -1 1 3 4 5 so count array will have 0 1 2 3 4 5 6 7 8 where 0 stores occurences of -3 , 2 stores occurences of -1 ... so on
@vashishthgajjar19684 жыл бұрын
wait what kind of sorting method is this?
@ServingTech4 жыл бұрын
In Your Coount_Sort Program You Cannot Sort The Negative Values.
@yashgandhi96984 жыл бұрын
can be done using origin shifting if a mixture of both +ve and -ve just reverse the sign in case of all negative...
@ServingTech4 жыл бұрын
@@yashgandhi9698 #include using namespace std; void Count_Sort(int arr[],int n, int Min,int Max,int ans[]) { int range=Max-Min+1; int farr[range]={0}; for(int i=0;i n; cout > arr[i]; Max = max(arr[i], Max); Min = min(arr[i], Min); } int ans[n]; Count_Sort(arr,n,Min,Max,ans); for(int i=0;i
@ServingTech4 жыл бұрын
Like This ?
@csiddharth3804 жыл бұрын
Bhaiya G plz is video k bhi notes upload krdo
@sakshithakur84654 жыл бұрын
Please upload notes 🙏🏻🙏🏻🙏🏻
@pranshuprapranshu3047 ай бұрын
you didnt told why you started , loop from i=1 and not from i=0 (~_~)
@TRICK_OF_THE_DAY Жыл бұрын
Why you don t have Persian subtitle?
@shravakjain51633 жыл бұрын
how can we think so far like that..? i am unable to solve new question
@jiosim13773 жыл бұрын
Bro all these sorting algorithms are standard algorithms u cant think on spot nd get the logic. U have to learn and remember the logic