This is one of your subscriber. I'm lucky to find your videos on youtube. Ive gone through every single video of yours that exist on youtube. Hands down content. Immensely satisfied. Nobody Nobody teaches better than you do. Could you please make more videos on topics like Trees-segment trees, Tries and graph. Please dont stop making videos. This world needs you and more like you(which I don't find anyone else other than you).
Thanks a lot brother !! Really this mean a lot to me, Thanks. And yeah I haven't stopped making video, just kind of stuck as of now due to lockdown. Definitely will be uploading more content in near future !!
@@TheAdityaVerma have completed your Videos on DP, Stack and going through heap.. please upload videos on Tree and Graph as well bhaiya... Immensely Immensely satisfied..
You are someone who gives any of the average student that confidence that even they can understand this programming concept . You are a great teacher .
Bhai Sahab! I have been a subscriber of you channel from the time there was 1k Subs on this channel. You are one of the best teachers who clears concept in simplest format! Awesome!
Never seen any tutor who put so much effort to make sure even small things are cleared by re-iterating multiple times. Thanks a ton for your content which is saving a lot of efforts scrolling over the internet or by wasting money on fraudsters. You should probably start as a full-time educator :)
Loved the "koi chakkar wali baat nahi hai sab samajh aa jayega 2 min mein" I am an SDE-2 in a Product Based startup and one thing that I have run away from is DSA. HLD, LLD round I can clear very easily but I always refrained from studying DSA. The interviews that mostly focused on system design were easily cleared but DSA-focused interviews were problematic for me. This series has been so clear and informative. Thanks a lot, Aditya for this valuable content. FAANG soon
Hi @sushant My case is exactly the opposite of yours. I always refrained from learning HLD, and LLD and one of the reasons is, that I never got any good resources for that. We have already got an awesome DSA playlist of Aditya, you can go through it. Please share some good resources to start HLD, and LLD if you have them. Thanks
your way of teaching is awesome..please make videos on backtracking and trie.Please continue making videos..earlier used to hate ds but because of your videos and lucid way of explanation I started enjoying it and able to solve lot of questions
Aditya u r a very fantastic teacher.So lucky that I found your vedios..bhott achi explaination...SB smjh aya....plz keep making such vedios on other DSA topics as well.
Implementation of heap in java Min Heap --> PriorityQueue pq = new PriorityQueue(); Max Heap --> PriorityQueue pq= new PriorityQueue(Collections.reverseOrder());
In other term Implementation of Heap in java Min heap --> PriorityQueue pq = new PriorityQueue(); Max heap --> PriorityQueue pq = new PriorityQueue((a,b)->b-a);
bhaiya 1 idea hai same heap (stl) ko use karne ka :- just reverse the sign i.e -1* (element) while inserting and while popping out again multiply it by -1 this way we can use same heap function(stl) for min and max heap correct me if I am wrong.. lekin bhaiya aik shanbd mai = "MAZA AA GAYA!" more such videos needed!
Bhaiya aap ki saari videos awesome he but aap ne kaha tha ki app graph and tree me se ekk topic suru karenge july 2021 se so please complete your promise we are waiting for graph and tree series. Thank you so much and lots of wishes for you.
Hi, I am a student from NIT-Durgapur and can't really express how helpful your DP videos have been. I am definitely sure the heap videos are gonna be great too. And as a subscriber I have one request..please maybe try uploading more videos on various Data Structures and Algorithms..
Are bhai tumi o durgapur a , naki bari chole gacho.... DP'r video gulo shotti e darun chilo, gfg te onek gulo practice korlam, tomar ki khobor, Actually amio DGP te tai excited hoye gachilam😂😂😂 Sorry to be creepy af😁
Hey Aditya, Please answer this. What if we use min heap instead of max heap I think it will give complexity as Klog(N) since we need basically two need steps first is to heapify the array using heapify (shift down heapify) which will take O(N) time and later pop k no. of nodes which will take O(Klog(N)) time. Isn't Klog(N) is better than Nlog(K) because we are putting N in log which is a bigger number and log will make it smaller which overall decrease the value of my expression . I really liked your video.
Will try !! Next is Binary Search tho !! I was asked a question in my flipkart interview regarding binary search so I though it would be better to get it done first.
correct me if im wrong but hum n times insertion perform kr rhe hain and heap ki insertion O(log n) time leti hai toh time complexity toh O(nlog n) yahan bhi hogyi jaise sorting mein thi, lekin agr hum kth smallest mein minheap banaye n size ka toh heap ka construct O(n) time lega then k-1 times pop krlein toh O(n+(k-1)log(k-1)) time mein solve hojayega. Is it correct ? Pls do tell edit: Sorry for the doubt i understood basically hum insert humesha log k size ke heap mein kr rhe hain toh hr operation ke liye max time log k lagega hence O(n log k) .Great concept indeeed 👏❤
As k is always lesser than n. So O(k log(n)) should be preferred over O(n log(k)) . So if we use the std::priority_queue (min) for kth smallest element with the predefined array. So making priority_queue will be O(n). then we can pop the k top elements . so it can be O(k log(n)) . can someone clarify this ?
The time complexity when we use min priority queue will be O(n+klog(n)) as we also need to include the complexity to create a min heap of n elements intially. So, the complexity will be more like linear (O(n)) than logarithmic. Hence the second method is preferred.
Hi @Adiya Verma, I read kth largest/smallest can further be optimized to O(N) instead O(NlogN) using the partition, could you please share the partition solution too if possible?
I think for kth smallest we will use min heap and for kth largest questions: max heap in JAVA Bcoz in java it's implemented via priority queue and u told by stack in c++. Correct me if I am wrong
I think if we use build heap that will take 0(n) and the retrieval of k elements will take 0(logk) . So the complexity will come down to 0(n+logk) which is equal to 0(logn).
no, when we create a heap using heapify it takes o(n) and when we remove k elements, each will take logn so the time complexity will be klogn. and what he is doing is not heapify, he is inserting elements one by one which will take nlogk time, even tho he is removing k+1th element, he is still inserting it before removing it. so idk which is better klogn or nlogk
At 13:37, you said that when the size of heap is greater than 'K', then we pop the top element and push the current element... But shouldn't it be something like we should pop the top element only if the current element is less than/ greater than (according to question) the top element? In this question, shouldn't we do something like this:- If (q.top()>arr[i]){ q.pop(); q.push(arr[i]); } I'm not sure, just asking. And again, thanks for this awesome content brother! Liking and sharing this channel. :)
We dont push, we assume by the implementation of the heap that the insertion happens perfectly in sorted order. Because of this we can safely always say that the largest element is at the top
I code in Python. If I want to use max heap or min heap without implementation which libraries should I use? Heapq is only for min heap. What about max heap?
If the Array is in decreasing order ie. [10,9,8,7,6,5,4,3,2,1] and K=3 , Then it will not work right as It will remove 10,9,8 in 3 iterations and on the last iteration it will return Top element which will be 7 but our answer is 3(as 3 is the 3rd smallest number). Can someone help me clear this doubt ?
Ans is 3 . k=3 means not to be 3 times iteration but iteration of every element present in the given array. max 3 elements present inside the heap.4 th element add hone ke bad top me Max value hoga wo pop ho jayega . I think it must be helpful to you .
Please can you make vedios on trees or tell me where can I study tree data structure (except for geeks ) for interview preperation. It will be a great help
The man, the icon, Aditya Verma. You taught me DP, I cleared Microsoft.
Hi can you please tell from where to do graphs and trees
This is one of your subscriber. I'm lucky to find your videos on youtube. Ive gone through every single video of yours that exist on youtube. Hands down content. Immensely satisfied. Nobody Nobody teaches better than you do. Could you please make more videos on topics like Trees-segment trees, Tries and graph. Please dont stop making videos. This world needs you and more like you(which I don't find anyone else other than you).
Thanks a lot brother !! Really this mean a lot to me, Thanks.
And yeah I haven't stopped making video, just kind of stuck as of now due to lockdown. Definitely will be uploading more content in near future !!
@@TheAdityaVerma have completed your Videos on DP, Stack and going through heap.. please upload videos on Tree and Graph as well bhaiya... Immensely Immensely satisfied..
@@TheAdityaVerma bhaiya plz graph and backtracking ka bhi bna do 🙏🙏
@@TheAdityaVerma plz upload make video on graph and tree the way u explain is awesome
@@TheAdityaVerma kb kroge bhaiya v waiting....
intern bhi to lgwani h
really love the u teach :)
You are someone who gives any of the average student that confidence that even they can understand this programming concept . You are a great teacher .
If someone is Thinking to go with this playlist I just wanted to say Don't think just go and learn its amazing
The real mentor of all tire-3 guys.... 🙏
Bhai Sahab! I have been a subscriber of you channel from the time there was 1k Subs on this channel. You are one of the best teachers who clears concept in simplest format! Awesome!
I am now your patron on Patreon. I never became a patron before. But looking at this content I think it is worth it.
Glad you think so Nikhil ✌️❤️
Never seen any tutor who put so much effort to make sure even small things are cleared by re-iterating multiple times. Thanks a ton for your content which is saving a lot of efforts scrolling over the internet or by wasting money on fraudsters.
You should probably start as a full-time educator :)
# HI BOSS
Boss I am also from your college (MACT).
BOSS Aapki video dekh kr dil khush ho gaya
best tutorial for heap, best teacher on youtube ,waiting for other data structures also
Flipkart ka base=16 hai or CTC 24 hai , best programming content on youtube ,big fan Aditya bro .
yaa man, we are waiting for your backtracking series and also Hashing. man you transforming lives over here . respect
Best explanation of Heap.I always had hard time in understanding Heap but finally understood it.
Please make more videos on Graphs and Strings.
Nice explanation sir....thanks for the playlist...doing a really great job..
Loved the "koi chakkar wali baat nahi hai sab samajh aa jayega 2 min mein"
I am an SDE-2 in a Product Based startup and one thing that I have run away from is DSA. HLD, LLD round I can clear very easily but I always refrained from studying DSA. The interviews that mostly focused on system design were easily cleared but DSA-focused interviews were problematic for me. This series has been so clear and informative. Thanks a lot, Aditya for this valuable content. FAANG soon
Bhai tum karloge crack maang easily. All the best.
Hi @sushant
My case is exactly the opposite of yours. I always refrained from learning HLD, and LLD and one of the reasons is, that I never got any good resources for that. We have already got an awesome DSA playlist of Aditya, you can go through it.
Please share some good resources to start HLD, and LLD if you have them.
Thanks
@@mayankmohit3414Gaurav Sen yt for system design, for documentation oo design website.
Layoff soon XD
@@pranav288 eggh what
Bhai itni acchi explanation ko dislike kaise kr lete hai log bhai ?
Excuse Me Sir
Good Evening Sir
Excuse me Sir
Love from NIT Bhopal Sir😇
why we do vextor in min heap @19:08
so after the dp series, back to your channel, literallly very vey excited for this series!!!!!
I just only say , THANKS MERE BHAI ❤❤
thank you for ypur videos they are better standard than paid courses
your way of teaching is awesome..please make videos on backtracking and trie.Please continue making videos..earlier used to hate ds but because of your videos and lucid way of explanation I started enjoying it and able to solve lot of questions
Just watched this heap playlist, Its superb !!
I really appreciate your work.
Pen n Paper > PC
plz plz send more and more viodes excellent ......one of the ever ds concept proud of u bade bhaiya
Best approach to identify a heap problem. Thanks a lot
best explanation of heap in all the videos i have seen on this topic
Aditya u r a very fantastic teacher.So lucky that I found your vedios..bhott achi explaination...SB smjh aya....plz keep making such vedios on other DSA topics as well.
Implementation of heap in java
Min Heap --> PriorityQueue pq = new PriorityQueue();
Max Heap --> PriorityQueue pq= new PriorityQueue(Collections.reverseOrder());
In other term Implementation of Heap in java
Min heap --> PriorityQueue pq = new PriorityQueue();
Max heap --> PriorityQueue pq = new PriorityQueue((a,b)->b-a);
🎉@@Abhisheksdt
Commiting myself to practice atleast 1 coding problem daily. Will be updating here! Kudos to your amazing efforts bhaiyaa
bhaiya 1 idea hai same heap (stl) ko use karne ka :- just reverse the sign i.e -1* (element) while inserting and while popping out again multiply it by -1 this way we can use same heap function(stl) for min and max heap correct me if I am wrong.. lekin bhaiya aik shanbd mai = "MAZA AA GAYA!" more such videos needed!
I watched your first video.good explanation.every student will be understand it.
Thanks a lot!Will complete this series today!
brother waiting for your backtracking series...
Yes bro
Your wish fulfilled after 3yrs. He started backtracking series few weeks back.
@@jonu.1504Exactlyyyy
abhi start bhi nhi kra mene apla video me smj gya aap bohot mst padhte ho
bhai big fan ,great work...your videoes are cristal clear bro...thanku for these videos
god level explaination of the time complexity! Have done heaps before but not with this clarity!! Please make a series on backtracking!
Bhaiya, apne heap ko stack se samjhaya par heap is a tree-based data structure. Confused.......plz reply
Please teach GRAPHS, I am having a hard time there
yes bhaiya
what exatly are u finding hard in graphs ? I guess topological sort , mst are some tough topics ??
@@aman-tl9gd would you tell me from where should i do Graph?
would you tell me from where should i do Graph?
Bhaiya pure DS ke playlist daalo na.
Aap jabardast samjhaate ho..great
i madara uchiha hereby declared you the finest and strongest dsa teacher in whole youtube
ok bro, starting this playlist after your comment. Was searching for a latest comment rest are yrs old.
Bhaiya aap ki saari videos awesome he but aap ne kaha tha ki app graph and tree me se ekk topic suru karenge july 2021 se so please complete your promise we are waiting for graph and tree series. Thank you so much and lots of wishes for you.
bhai ki class bole to ek number!!!
Dheeraj rakhe, koi chakkar wali baat nahi hein, abhi samajh mein ayega 2 minute mein😅😂
Thanks for the wonderful explanation bhai!
This guy is such a gem>>>>>>
Hi, I am a student from NIT-Durgapur and can't really express how helpful your DP videos have been. I am definitely sure the heap videos are gonna be great too. And as a subscriber I have one request..please maybe try uploading more videos on various Data Structures and Algorithms..
Are bhai tumi o durgapur a , naki bari chole gacho.... DP'r video gulo shotti e darun chilo, gfg te onek gulo practice korlam, tomar ki khobor, Actually amio DGP te tai excited hoye gachilam😂😂😂 Sorry to be creepy af😁
Hey Aditya, Please answer this. What if we use min heap instead of max heap I think it will give complexity as Klog(N) since we need basically two need steps first is to heapify the array using heapify (shift down heapify) which will take O(N) time and later pop k no. of nodes which will take O(Klog(N)) time.
Isn't Klog(N) is better than Nlog(K) because we are putting N in log which is a bigger number and log will make it smaller which overall decrease the value of my expression .
I really liked your video.
No, let say if k ~ N then your algo will take ~ O(N logN) but aditya's algo will take ~ O(N)
@@VishalSharma-hq5ti That is correct. But if k
@@vishvapatel3641 and not to mention, the k usually IS
Is this aproach enought to solve "Minimum adjacent steps to reach the Kth smallest number"??
Thanks bro , please make a playlist on linked list and trees ..
Will try !! Next is Binary Search tho !! I was asked a question in my flipkart interview regarding binary search so I though it would be better to get it done first.
correct me if im wrong but hum n times insertion perform kr rhe hain and heap ki insertion O(log n) time leti hai toh time complexity toh O(nlog n) yahan bhi hogyi jaise sorting mein thi, lekin agr hum kth smallest mein minheap banaye n size ka toh heap ka construct O(n) time lega then k-1 times pop krlein toh O(n+(k-1)log(k-1)) time mein solve hojayega. Is it correct ? Pls do tell
edit: Sorry for the doubt i understood basically hum insert humesha log k size ke heap mein kr rhe hain toh hr operation ke liye max time log k lagega hence O(n log k) .Great concept indeeed 👏❤
loved your paper & pen tricks.
more valuable than a paid course
17:48 implement karne me aisi ki taisi ho jayegi.. cant stop laughing. :D
This is really good for revisions!
As k is always lesser than n. So O(k log(n)) should be preferred over O(n log(k)) . So if we use the std::priority_queue (min) for kth smallest element with the predefined array. So making priority_queue will be O(n). then we can pop the k top elements .
so it can be O(k log(n)) .
can someone clarify this ?
The time complexity when we use min priority queue will be O(n+klog(n)) as we also need to include the complexity to create a min heap of n elements intially. So, the complexity will be more like linear (O(n)) than logarithmic. Hence the second method is preferred.
@@RaviSingh-qd5pz hi , but O(nlogk) is more than linear . With k > 2
@@RaviSingh-qd5pz But then we need to create maxheap, and it also consume time for heapify. Thoughts?
bhaiya graph par kuch videos banayiye
Wow excellent teaching😇
Great video boss
7:00 But in worst case when k == n; then the nlogk will become nlogn --> Then we can use sorting too right?
Hi @Adiya Verma, I read kth largest/smallest can further be optimized to O(N) instead O(NlogN) using the partition, could you please share the partition solution too if possible?
Hey buddy nice job, really nice explanation 🔥🔥
Ye banda, medical walo ko bhi software engineer bna dega. I guarantee.
I am lucky to find your videos 🤩🤩
by adding all elements to the heap, the complexity anyways became nlogn as one insertion in heap is logn. Im not sure how nlogn becomes nlogk.
if we do in c, for kth/k smallest we can do min heap. For kth/k largest we can do max heap only
what's the basic difference between heap and priority_queue
Cool video... So clearly explained bro 😊
Please make vedeos on graph and trees
Thank you, I will try !!
I think for kth smallest we will use min heap and for kth largest questions: max heap in JAVA
Bcoz in java it's implemented via priority queue and u told by stack in c++.
Correct me if I am wrong
u r right man,the same mistake he did in dp series where he mixed up memoization with tabulation.
Amazing explaination
I think if we use build heap that will take 0(n) and the retrieval of k elements will take 0(logk) . So the complexity will come down to 0(n+logk) which is equal to 0(logn).
no, when we create a heap using heapify it takes o(n) and when we remove k elements, each will take logn so the time complexity will be klogn. and what he is doing is not heapify, he is inserting elements one by one which will take nlogk time, even tho he is removing k+1th element, he is still inserting it before removing it. so idk which is better klogn or nlogk
bt ismei radix sort se O(n) ki complexity bhi to achieve kr skte h?
Best content 👍
Please make series on graph and hashing.
just to add we can also use quick select method in these type of problems that run on average O(n)
Nice explaination bro, keep making videos on DS, Algo.
Thanks ! Yeah work is at progress !!
Please like the video to help it reach to more audience.
@@TheAdityaVerma very nice..when are the next set videos coming?
@@skmn07 did you watch all of it bro?
next is binary search and coming soon
@@TheAdityaVerma cool. Can you pls post tutorials on greedy problems and graph problems
Bhai recursion aur backtracking ki bhi upload kardo
please make videos on trees .I have completed stack playlist binary search .
Aditya Bhaiya OP hai :)
Love you brother.Your video is very helpful
Thank you
Plz upload more on trees🌳 graphs... 🙂
At 13:37, you said that when the size of heap is greater than 'K', then we pop the top element and push the current element... But shouldn't it be something like we should pop the top element only if the current element is less than/ greater than (according to question) the top element? In this question, shouldn't we do something like this:-
If (q.top()>arr[i]){
q.pop();
q.push(arr[i]);
}
I'm not sure, just asking.
And again, thanks for this awesome content brother! Liking and sharing this channel. :)
We dont push, we assume by the implementation of the heap that the insertion happens perfectly in sorted order. Because of this we can safely always say that the largest element is at the top
Bhai hasing and map ka playlist banado please
Bhaiya you don't have any playlist of sorting ?
I code in Python. If I want to use max heap or min heap without implementation which libraries should I use?
Heapq is only for min heap. What about max heap?
use negative values on the heap.
Bhau heap , heap sort ,quick sort ye sab implementation DSA interview k liye kitna imp hia?
your channel will be viewed by everyone so ,its should be useful hoping u will reach out in English..
If the Array is in decreasing order ie. [10,9,8,7,6,5,4,3,2,1] and K=3 , Then it will not work right as It will remove 10,9,8 in 3 iterations and on the last iteration it will return Top element which will be 7 but our answer is 3(as 3 is the 3rd smallest number). Can someone help me clear this doubt ?
Ans is 3 . k=3 means not to be 3 times iteration but iteration of every element present in the given array. max 3 elements present inside the heap.4 th element add hone ke bad top me Max value hoga wo pop ho jayega . I think it must be helpful to you .
@@payalbhattamisra6985 Yes I figured it out later. Thanks
@prabhat pandey most welcome 😊
Bro we need more video on different topics love from Haryana 😘
Please upload videos on tree and graphs
Please can you make vedios on trees or tell me where can I study tree data structure (except for geeks ) for interview preperation. It will be a great help
You are too good to be true.
Bhaiya sets, priority queue, quick select algorithm.. In par bhi videos banao please
One question, we were trying to pop elements if size of stack > k, why dont we stop reading elements once size == k?
There can be further smaller elements in array, that's why we traverse the whole array and stop at the end taking the top of heap as answer
waiting for backtracking series...btw love to watch ur vdos
Can anyone please tell me this dsa playlists are in c/c++ or java ???
Can someone tell me ,will these videos on heap is enough for basic understanding??
bro apne kya ashish vishnoi sir se jee ki preperation ki thi...because of teaching idea
For Java devs declarations are:
PriorityQueue maxHeap = new PriorityQueue(Collections.reverseOrder());
PriorityQueue maxHeap = new PriorityQueue();
Thanks brother
dono ko maxheap bol diya...wah bhai!
plz bro keep on making such video😊
Thank you aditya bhaiya