CORRECTION: at 42:50 heapify call for delete logic would be maxheapify(A, i-1,1) and in maxheapify method instead of while loop we can write if statement. :)
After correction also sorted output in not coming ! ----------------------------------------------------- #include void printArray(int *A, int n) { for (int i = 0; i < n; i++) { printf("%d ", A[i]); } printf(" "); } void swap(int *A, int i, int j) { int temp; temp = A[i]; A[i] = A[j]; A[j] = temp; } void maxHeapify(int *A, int n, int i) { int largest = i; int l = (2 * i); int r = (2 * i) + 1; if (l A[largest]) { largest = l; } if (l A[largest]) { largest = r; } if (largest != i) { swap(A, largest, i); maxHeapify(A, n, largest); } } void heapSort(int *A, int n) { { int temp; for (int i = n / 2; i >= 1; i--) // build max heap { maxHeapify(A, n, i); } for (int i = n; i >= 1; i--) // deleting { swap(A, 1, i); maxHeapify(A, i - 1, 1); } } } int main(void) { int A[] = {4, 6, 1, 2, 45, 12, 40}; int n = 7; printArray(A, n); heapSort(A, n); printArray(A, n); return 0; }
I’ve subscribed and turned on notifications and you didn’t even have to ask for it. That’s the mark of a quality uploader. Thank you for sharing your valuable knowledge.
First I watched your CountingSort video...then didn’t stop watching your other videos. Thats the quality of your videos. This generation students are very lucky to have open university and talented lecturer like you in youtube. In reality all the students wont get best teacher in their classrooms. Kudos to your work, keep doing 🙏, I read so many program sites couldn’t explain clearly like you explain the example with all the iteration passes. Doing 1 or 2 iteration passes will not give deep understanding of the solution. 🙌🏻
Also I for the life of me could not understand why to take n/2 as the starting point, while looking at a piece of code for Heap sort. You explained that critical bit of info with a use case. Thank you!
No other person can explain these algorithms better than Jenny Mam. Everything is explained beautifully with pictorial representation as well as with code. Thanks a lot Mam!
Excellent video. The concept of heap sort and heapify is easy to understand but the code can be a little complex to come up with. I tried for 3 hours and watched numerous videos and stumbled upon this gem. You earned a follower! Thank you so much!
Explantation is excellent and simplified way. At (42 min)in delete method looping should start with (i=n-1) if its start with n it will give one garbage value in array
Thank you, I really appreciate the fact that you are taking the time to do these videos, which is really good quality, top information regarding algorithms. You are an amazing teacher, I am sure you put in loads of hard work to come up with a method and solution which is easy to understand.
First for all we are converting our array into heap using heapify method. In heapify the we are starting from none leaf node so we are eliminating leaf node therefore we have used i=n/2; and we passing parameter as I. And in other for loop we are going to sort the heap and here we going to use deleting root node method for sorting therefore we passed 1 instead of i. Thankyou Ma'am. You're teaching is very nice.🥰
It took me a long time to understand what she is saying ! Not because she is bad at explaining , I was just not able to hear anything once I saw her . Btw ! Thanks for the info . Keep it up.
What a great explanation Jenny! Was thinking to skip heap sort thinking its 46 min explanation but actually worth it! Now I know heap sort from leaf to root xD
Hello api,, i am from Bangladesh.. I have seen many videos about heapsort 😪😪but none of this could able to explain the algorithm as clearly+easily as you....😊😊 You lecture just amazing💚💚💚 api❤❤ and very much helpful to me. I am very grateful to you. 🥰🥰 Also expecting more lectures about data structure and algorithm from you..🥰😻😻😻💚💚
"maxheapify method instead of while loop we can write if statement. :)" Glad you corrected this yourself, I was about to correct you there. But its ok because Approach is right, I understand it is difficult to code when not using an IDE.
@Jenny's lectures CS/IT NET&JRF A small correction, in the logic of sorting loop, instead of maxHeap(A, i-1, 1) we have to use maxHeap(A, i-1, 0) because the index starts from 0 and our first element will always be at index 0.
I think In the deletion part the call to heapify must be like: MaxHeapify(A,i-1,1); As if we pass n after execution it will put 15 in last again and 30 in middle so tree would not be MaxHeap anymore. And seperate from it Thankyou for being such awesome teacher😇
that last part were you said it is heap sort....that was like magic..i was afraid of heap sort thought it was difficult but you explained it so magically
you are a wonderful teacher. My whole DSA basic I clear from this channel. thanks mam. and request you to bring more content related to university subjects.. 😇🙂
Your lectures are awesome, easy to understand and with every aspect covered. I am able to learn algorithms only because of your lectures. However, just wanted to point out a couple of really minor mistakes in the code and hence the logic. 1. We need to call the swap method in MaxHeapify method within each of the while loops. If we have an array - 2|500|300, calling swap just once outside the while block will result in - 300|500|2 which is not a max heap. 2. In our main HeapSort method, when we are doing the "deleting and building" logic, we need to call the MaxHeapify, written after the swap, as - MaxHeapify(Array, i-1, 1) i.e. instead of passing the entire length "n", we need "i-1". The reason is : i = n at the start of this loop. So after the very first swap, our last index is already a sorted array. Hence, we need not call the Maxheapify method on entire array. Instead, just call this method for the remaining elements. I hope this is clear enough. Thanks once again mam for posting these videos! :)
I asked sorting in an mnc interview and and I passed it with flying colours✨✨ because of your vedios mam thanks alot Jenny mam for this excellent explanation 😍😍
Thank you ma'am. Your videos had helped me a lot before my exam. From your videos I could understand clearly. After that I recommended your videos to some of my friends too
@@BSEss It would be wrong as we are making the swap first and calling the Heapify. For instance, if you include the n on the first iteration of Heapify, it would be swapped with its parent (n/2).
Preparing for interviews. I am told I have to be very good with DS. Been watching only your and Abdul Bari's videos for preparation. Good work, keep it up! Very easy way to explain.
Today is my paper and I am so much confused about paper 🤣 firstly I think that I can,t perform good in paper . but now I am watching your videos to solve paper .so , finally I can say that I can perform best in paper🤩🥰.thanku mam💕❤️💖
Mam a lot help full you'r lectures me and myfriends .upcoming generation teachers be like you teaching.so much better. I never forget you mam because.Internet using any work is done .this is possible. I proudly say.
Hey . You are very good teacher. your way of teaching is outstanding. lot of pakistani students follow your lectures and get good marks in exams. Outstanding
CORRECTION: at 42:50 heapify call for delete logic would be maxheapify(A, i-1,1) and in maxheapify method instead of while loop we can write if statement. :)
Thanks!
👍
👍
After correction also sorted output in not coming !
-----------------------------------------------------
#include
void printArray(int *A, int n)
{
for (int i = 0; i < n; i++)
{
printf("%d ", A[i]);
}
printf("
");
}
void swap(int *A, int i, int j)
{
int temp;
temp = A[i];
A[i] = A[j];
A[j] = temp;
}
void maxHeapify(int *A, int n, int i)
{
int largest = i;
int l = (2 * i);
int r = (2 * i) + 1;
if (l A[largest])
{
largest = l;
}
if (l A[largest])
{
largest = r;
}
if (largest != i)
{
swap(A, largest, i);
maxHeapify(A, n, largest);
}
}
void heapSort(int *A, int n)
{
{
int temp;
for (int i = n / 2; i >= 1; i--) // build max heap
{
maxHeapify(A, n, i);
}
for (int i = n; i >= 1; i--) // deleting
{
swap(A, 1, i);
maxHeapify(A, i - 1, 1);
}
}
}
int main(void)
{
int A[] = {4, 6, 1, 2, 45, 12, 40};
int n = 7;
printArray(A, n);
heapSort(A, n);
printArray(A, n);
return 0;
}
I came here to tell this. I have been trying to solve this problem for 3 hours.
Anyway, thank you.
The beauty of these lectures is that even faculty learns from here to teach their students....you are amazing mam....
So basically we're all going to university to get our degree but we learn all the stuff from youtube tutorials.
yep and always from a smart person from india, but at least this woman is beautiful!
Yeah welcome to understanding India's Education System
true, university is just an outline :D
@@tungtruong5904 true said bro college sirf namki he lekin sab log asli padhai youtube parshe hi karte
ive watched so many indian youtube tutorials , ima get hindi degree till end of college
I’ve subscribed and turned on notifications and you didn’t even have to ask for it. That’s the mark of a quality uploader. Thank you for sharing your valuable knowledge.
Agreed
Spam
First I watched your CountingSort video...then didn’t stop watching your other videos. Thats the quality of your videos. This generation students are very lucky to have open university and talented lecturer like you in youtube. In reality all the students wont get best teacher in their classrooms. Kudos to your work, keep doing 🙏, I read so many program sites couldn’t explain clearly like you explain the example with all the iteration passes. Doing 1 or 2 iteration passes will not give deep understanding of the solution. 🙌🏻
Also I for the life of me could not understand why to take n/2 as the starting point, while looking at a piece of code for Heap sort. You explained that critical bit of info with a use case. Thank you!
No other person can explain these algorithms better than Jenny Mam. Everything is explained beautifully with pictorial representation as well as with code. Thanks a lot Mam!
Excellent video. The concept of heap sort and heapify is easy to understand but the code can be a little complex to come up with. I tried for 3 hours and watched numerous videos and stumbled upon this gem. You earned a follower! Thank you so much!
Explantation is excellent and simplified way.
At (42 min)in delete method looping should start with (i=n-1) if its start with n it will give one garbage value in array
Thanks mam. Passed my 3 semesters by watching your videos. 🙏♥️
You are only in UA-cam who explained this algorithm in structured and easy way.👍
Actually i want to give as many as likes possible for your lecture but here he gave only one.....😍😍
Most valuable gem of IT and data Science : Jenny Ma'am 😊
Thank u mam for that grt video.
Aap hi ho meri real DSA waali mam.
My dsa marks credit goes to you only.
Love you mam
Paying lakhs in the college and these UA-cam videos are more helpful than my entire life
mam u taught like god...
each concept is now embedded in me.
Always wearing a watch is often seen as a symbol of responsibility, punctuality, and attention to detail.I love it mam.
Thank you, I really appreciate the fact that you are taking the time to do these videos, which is really good quality, top information regarding algorithms. You are an amazing teacher, I am sure you put in loads of hard work to come up with a method and solution which is easy to understand.
My university lecturer play your video in class and teach us algorithms 😂❤
🤣
@@sushmapandey7145 😂
O bhai...
@@sushmapandey7145 😂😂😂
Waste of money in your University
First for all we are converting our array into heap using heapify method.
In heapify the we are starting from none leaf node so we are eliminating leaf node therefore we have used i=n/2; and we passing parameter as I.
And in other for loop we are going to sort the heap and here we going to use deleting root node method for sorting therefore we passed 1 instead of i.
Thankyou Ma'am.
You're teaching is very nice.🥰
I sometimes feel very happy that I m preparing for GATE2020😍😍really very clear explanation thankyou!
Did you cracked it?
Yeah....same question....did you cracked it??
Did you crack
You really are one of the best teachers for data structures and algorithms.
Mam Jinny Thank you sooo Much agaar ap na hoti tou data structure ka course parhana bhot mushkil Hota Huge respect for you mam .Luv From Pakistan
Mam you r 100000 times better than my college mam..your presentation techniques is very pleasant..thank you mam to teach us in this way.❤
My college professor and your explanation is very easy
The last dry run has cleared my doubt. Mam you are gem for us.
i am leaning itpec and when i see your videos of all , more easy to learn and have a graet solutions for exam . i really really appreciate .
It took me a long time to understand what she is saying ! Not because she is bad at explaining , I was just not able to hear anything once I saw her .
Btw ! Thanks for the info . Keep it up.
What a great explanation Jenny! Was thinking to skip heap sort thinking its 46 min explanation but actually worth it! Now I know heap sort from leaf to root xD
Leaf to root XDDD
Was preparing for the internship drive(interview season), wanted a heap & heapsort revision and here it is. Saved once again :)
So how was your interview...??😬
@@vishaldas5692 lol😂 I got internship 🙌😇
@@himanshuyadav7327 Haha great u got on this covid situation....!!🥳
Indians always have the best programming content
One of the best teacher on you tube. Thanks mam for all your efforts u put for students and keep making such videos.
Being a teacher,, you are good at your job... Let us enjoy and learn well... Fantastic..
27:26 will start from here for revision
Thanks for clearing my doubts
...ur teaching stye is unique
beauty with brain --- deadly combination
Simplest logic explanation for complex function maxHeaify(). You are great Maam
mam ur voice is soothing to my ears, very pleasant to have u as a teacher.
Hello api,, i am from Bangladesh..
I have seen many videos about heapsort 😪😪but none of this could able to explain the algorithm as clearly+easily as you....😊😊
You lecture just amazing💚💚💚 api❤❤ and very much helpful to me. I am very grateful to you. 🥰🥰
Also expecting more lectures about data structure and algorithm from you..🥰😻😻😻💚💚
"maxheapify method instead of while loop we can write if statement. :)"
Glad you corrected this yourself, I was about to correct you there. But its ok because Approach is right, I understand it is difficult to code when not using an IDE.
@Jenny's lectures CS/IT NET&JRF A small correction, in the logic of sorting loop, instead of maxHeap(A, i-1, 1) we have to use maxHeap(A, i-1, 0) because the index starts from 0 and our first element will always be at index 0.
Here index 0 contains sentinel value bro so we start from index 1 only
tremendous lecture on heap sort. Highly recomended.
Wonderful teaching I am now just able to remember after listening only one time and cuteness overloaded
U r awesome mam....... tomorrow I have a sem 3 ....iam super satisfied with ur explanation mam tq......
I think
In the deletion part the call to heapify must be like:
MaxHeapify(A,i-1,1);
As if we pass n after execution it will put 15 in last again and 30 in middle so tree would not be MaxHeap anymore.
And seperate from it
Thankyou for being such awesome teacher😇
Jenny your lectures are such great help! I’m relieved to have found your channel! Thank you for being so thorough with your explanations :)
that last part were you said it is heap sort....that was like magic..i was afraid of heap sort thought it was difficult but you explained it so magically
insert O(nlogn)
delete O(nlogn)
20:30 leaf node
25:38 O(n)
35:00 pseudocode of O(n) | heapify
42:42 heap sort | O(nlogn)
super mam you was mother of data structures
you are a wonderful teacher. My whole DSA basic I clear from this channel. thanks mam. and request you to bring more content related to university subjects..
😇🙂
Your lectures are awesome, easy to understand and with every aspect covered. I am able to learn algorithms only because of your lectures.
However, just wanted to point out a couple of really minor mistakes in the code and hence the logic.
1. We need to call the swap method in MaxHeapify method within each of the while loops. If we have an array - 2|500|300, calling swap just once outside the while block will result in - 300|500|2 which is not a max heap.
2. In our main HeapSort method, when we are doing the "deleting and building" logic, we need to call the MaxHeapify, written after the swap, as - MaxHeapify(Array, i-1, 1) i.e. instead of passing the entire length "n", we need "i-1".
The reason is : i = n at the start of this loop. So after the very first swap, our last index is already a sorted array. Hence, we need not call the Maxheapify method on entire array. Instead, just call this method for the remaining elements.
I hope this is clear enough. Thanks once again mam for posting these videos! :)
Jyada angrezi nahi jhaadni chahiye
Didi your teaching procedure by English communication is A1 .. lv from west bengal didi ❤
Great lecture. Concept Explained in simplest terms. Thank you, Jenny
Thanks a lot for this lacture. Your videos help me alot for my exams and you explain in a very good manner thanks once again.☺😊
There should be if clause instead of while, because we dont need loop. we are just comparing the values.
Yea
wow .. nice explanation.. i shared this video in my class group
I asked sorting in an mnc interview and and I passed it with flying colours✨✨ because of your vedios mam thanks alot Jenny mam for this excellent explanation 😍😍
Wow great congratulation 🥳❣️
@@vishaldas5692 thanks bro 🤜
her teaching style is same as my college professor. just amazing
Thank you ma'am. Your videos had helped me a lot before my exam. From your videos I could understand clearly. After that I recommended your videos to some of my friends too
Always end up watching your video every SINGLE time. Thank you so much for all your tutorial.
mind blowing explaination...now am big fan of you
That was amazing explanation; i was so stuck in heap sort part :,) thanks
Thanks. Keep up the good work.U just saved my semesters
Maam, your way of teaching is awesome. Thanks a lot.
thank u miss , im computer sci student , this is very helpful
In the deletion, our array size remained same as we are sending n in it!!
Isn't it wrong,
I think Maxheapify(A,i-1,1) would be there?
Correct bro.
And one more thing in place of while loops there will be simple if condition in heapify function.
Thank you so much brother......I had the same doubt ....
Yes you r correct because after swapping 1st element with n th. Element. We have to heapify only at n-1, otherwise it will again heapify whole array
@@akshatkumar2956 But bro i-- to already loop mein ho raha ha so shouldn't we write (A, i, 1) ?
@@BSEss It would be wrong as we are making the swap first and calling the Heapify. For instance, if you include the n on the first iteration of Heapify, it would be swapped with its parent (n/2).
It's a very good explanation. Keep up the good work, madam.
Amazing explanation mam , no one can replace mam ! Almost k watched your videos it's very useful and understandable
Preparing for interviews. I am told I have to be very good with DS. Been watching only your and Abdul Bari's videos for preparation. Good work, keep it up! Very easy way to explain.
I learn Programing bcz of u,after failing before 8 yr ago,ummid jag gayi hai
I love your way of explanation and your voice!
39:22 is important....... Thanks for this easiest explanation........
one of the best Explanation i ever heard
😍❤
Thank U❤ Angel❤
Video is long but worth it 👍 thanks ma'am we study a lot with yr lecs 👍
Tyvm for explaining such a complex operations in a simple and effective way
Very good lecture this helped me alot in my exam to score better thankyou so much
Wow , mind blowing 😊😊😊 what a explaination
we are going to college for completing 75%attendance but there nothing to learn but actually we learn from you tube❤❤
Today is my paper and I am so much confused about paper 🤣 firstly I think that I can,t perform good in paper . but now I am watching your videos to solve paper .so , finally I can say that I can perform best in paper🤩🥰.thanku mam💕❤️💖
Mam you are really a true teacher ❤ and your are very helpful 😊
Thq so much mam , code bhi smjh me aa gya clearly......thq so much
Tomorrow is my exam ...really only u helped a lot ❤
You are really good in teaching!
Thanks ma'am for all the videos. It helps a lot for solving all the problems in ADA nd DS.
Ma'am your teaching is just amazing and brilliant 👏
U re explanation is super
Mam your explanation is always so simple and easy to understand thank you for putting these video's on UA-cam :)
Good explanation with technical approach..
Me: Where can I learn Heap sort?
Jenny: Here only.
आप सभी देखने वालों से निवेदन है, एक बार मेरे चैनल पर आकर ज़रूर देखें
ua-cam.com/users/AtharDhamtariplaylists
@@Atharhashmisir lots of playlists...good content..wish u all the best..
Mam a lot help full you'r lectures me and myfriends .upcoming generation teachers be like you teaching.so much better. I never forget you mam because.Internet using any work is done .this is possible. I proudly say.
The concept and the understanding the code by you is great
Hey . You are very good teacher. your way of teaching is outstanding. lot of pakistani students follow your lectures and get good marks in exams. Outstanding
Wonderfull explanation I can understand very well from your classes
My college faculty copying your lectures mam😂
Same 🤣
Same😂
C benaya tumko
Aap. Bahut Sundar padhati hai 🙏🙏🙏🙏🙏
I watching many videos but not understand that video very help for me
Very nice explanation....I am from babasaheb bhimrao ambedkar university...u are much better than my professors...
Awesomeness appreciated👍🏻👍🏻👍🏻💯💯💯 Thanks a lot 🙏🏻🙏🏻🙏🏻
till now all the videos helped me so much
Mam your explanation so nice.
It's very helpful for me .
You are doing a great job.
Thanq mam 😍