Lecture 76: Heaps in C++ || Interview Questions || Part - 2
In this Video, we are going to solve a lot of Problems based on Binary Heaps.
There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “
Visit Crio: www.crio.do/redeem/781e2f5/
Discord Server Link: / discord
Course Flow: whimsical.com/dsa-4-placement...
Notes Link: drive.google.com/drive/folder...
Slides Link: drive.google.com/file/d/1E9IV...
Code Links: github.com/loveBabbar/CodeHel...
Questions Links:
- Kth Largest Sum Subarray: www.codingninjas.com/codestud...
- Merge K sorted Arrays:www.codingninjas.com/codestud...
- Merge K sorted Linked List: www.codingninjas.com/codestud...
Do provide you feedback in the comments, we are going to make it best collectively.
Connect with me here:
Instagram: / lovebabbar1
Twitter: / lovebabbar3
Telegram Group Link: Love Babbar CODE HELP
telegram.me/lovebabbercodehelp
My Editor: rishu.rsing...
Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.
Timestamps:
00:00 - Question 1
02:50 - Promotion
03:40 - Approach #1
09:55 - Approach #2
12:05 - Code
15:40 - Question 2
17:00 - Approach #1
19:50 - Approach #2
22:50 - Code
33:35 - Question 3
35:10 - Approach #1
37:49 - Approach #2
41:30 - Code
#DSABusted #LoveBabbar
Пікірлер: 213
TC of first q is O(N^2 log(k)), N^2 since two loops and log k to heapify it.
@ayushsinha5512
6 ай бұрын
k will be very small
Ek or puree youtube ka sabse best lecture
if today i get the job its because love bhaiya .you are such an amazing mentor i have ever seen.
Overdose hogaya bhaiya😂😂. Lekin usi baat ke to package hai. Btw jordar content bhaiya, jitni tareef karu utni kamm hai
consistency dono ka high hai bhaiya.... thanks
Waiting for the video since two days. Thank you for it
Thanks for this helpful lecture i am salute you for your consistency and i also try my best to be consistent
your content is really very awesome helping a lot of students. Thank you for this course. thanks a lot
@RaghavSharma-ln1qj
5 ай бұрын
😊1❤❤❤❤❤
*In 1st question* T.C will decrease O(N^2Log(k))
@alexrcrew1975
2 жыл бұрын
it will increase if k is greater than 10 it will increase the time
@adityaawasthi7694
2 жыл бұрын
@@alexrcrew1975 pls explain
@Shivam-kz2dg
Жыл бұрын
@@alexrcrew1975 why 10 why not 2 ? Log we take here has base val 2
@priyanshkumariitd
4 ай бұрын
Yes T.C. of heap solution is O(n^2 . log(k))
Thank You Bhaiyaaa!!, Now you are MY FAVOURITE on this platform!❤
dil se maja a raha hai bhaiya ... best course
best explaination for merging of k sorted arrays and list 😍😍😍😍
hats off bhaiya. thanks a lot for providing such top notch content.
wahh bhiyaa maza aa gya subkuch samaj bhi aya nice....
Thankyou bhaiya so much for this course
kya baat hai bhaiayaaa thanks a lot😍😍😍
Bhaiya maza agya video dekhke 😍
completed bhaiya tnku soooooo much for this handsome series
Thank you Love Bhaiya 🎆
thank you bhaiya , consistency op bhiaya
Thanks for this helpful lecture
Ques 2 : Alternate Approach without using HEAP. vector merge(vector &a , vector &b){ vector ans; int n = a.size(); int m = b.size(); int i = 0 , j=0; while(i
@prathamdwivedi106
6 ай бұрын
To bina heap ke to jyade aacha hua na ? heap use karke n*klogk lag raha hai
#BELIEVEINBABBAR I saw that gonna be green screen from next videos QUALITY++ NOTE : ONE MORE THING PLEASE INCREASE YOUR MIC VOLUME MANY PEOPLE WANT THAT
Present bhaiya with lot's of love for you
Quite complex codes today but uprading🤓
Thank you so much bhaiya!
Waiting for the video since two days. Thank you for it ❤❤
Great explaination
Ques 2) Alternate approach without using heap vector merge2Arrays(vectorarr1, vector arr2) { vector ans; int n1=arr1.size(); int n2=arr2.size(); int i=0,j=0; while(i
@tarakmheta8856
9 ай бұрын
what is the time and space complexity of this approach??
Present bhaiya❤🔥
Very helpful bhaiya
Thank you so much bhaiya😇
Thank you bhaiya
awesome content ...
Another approach for problem 2: i) push all the elements in a resultant vector in any order ii) Apply heapify algorithm to convert the resultant array into a max heap iii) Apply heap sort on the the resultant array to get the sorted array. Code: class Solution { private: void heapify(vector&ans, int i, int n){ int largest = i; int left = 2*i+1; int right = 2*i+2; if(left largest = left; } if(right largest = right; } if(largest != i){ swap(ans[largest],ans[i]); heapify(ans, largest, n); } } void heapSort(vector&ans, int size){ while(size != 1){ swap(ans[0],ans[size-1]); size--; heapify(ans, 0, size); } } public: //Function to merge k sorted arrays. vector mergeKArrays(vector arr, int k) { if(k == 1) return {arr[0]}; //Egde case vectorans; for(int i = 0; i for(int j = 0; j ans.push_back(arr[i][j]); } } int n = k*k; for(int i = n/2-1; i >= 0; i--){ heapify(ans, i, n); } heapSort(ans, n); return ans; } }; T.C. :- O(n2) + O(n) for heapify + O(nlogn) for heap sort = O(n2) S.C. :- O(K * K) P.S. :- Thanks love bhaiya❤
@arijitdubey
5 күн бұрын
Bro I think the time complexity of your code will also be O(K^2 . Log K) only because you are forgetting that when you apply heap sort, the size of this vector would be K^2. Thus, you are basically doing the brute force approach only, that is, traversing the matrix and then putting all elements into a new vector then applying a sorting algorithm to it. Thus it is not the optimized approach. (Although the time complexity of brute force only differs by a factor of 2.)
1st question by second approach T.C--O(n^2)
If you are feeling difficult Love's code try to understand this one T(C)= O(K^2 * log(K)) s(c)=o(k) vector mergeKArrays(vector arr, int k) { vectorans; priority_queueminh; for(int i=0;i1) { minh.push({arr[row][1],row}); // Increment the index of the current row to move to the next element in the row. arr[row].erase(arr[row].begin()); } } return ans; }
@Viralmems_xyz
9 ай бұрын
nice bro
@amaan1180
9 ай бұрын
Bhai plz also provide merge linked list code in this format
@Mohitkumar-un1ix
9 ай бұрын
@@amaan1180 Node * mergeKLists(Node *arr[], int K){ if(K == 1) return arr[0]; for(int i = 1; i Node* ord = new Node(-1); Node* tail = ord; Node* left = arr[i - 1]; Node* right = arr[i]; while(left && right){ if(left->data data){ tail->next = left; tail = left; left = left->next; } else{ tail->next = right; tail = right; right = right->next; } } while(left){ tail->next = left; tail = left; left = left->next; } while(right){ tail->next = right; tail = right; right = right->next; } arr[i] = ord->next; } return arr[K - 1]; }
going to end up dSA course with lots of learnings
Thanku Sir 🙏
Thnaks a lot Bhaiya.....RESPECT++;
Course kab khatam hoga bhaiya 😃😃 actually offline hogya college isliye poochaa 🤕 warna poora mazaaa aata he Lectures me ...
Thank You So Much BHRATA SHREE !!!!!!!
Professor Babbar is Back!!!
very heapful video!
Great lecture
Thank you :)
loved it
Present bhaiya
Hi, i am using java for all these questions. Now lets say in this question you asked to sort the array, in such case can we use the sort method provided by java or we need to use the trivial looping method for sorting
Before 19 April i will catch your consistency 😁
Amazing👍
Thanks bro👍
Mast sir Ji
Maje aagye sir aaj
I'm pretty sure I'm going to crack big companies interview one day. Thank you bhaiya for such videos.
thanku bhaiya
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exists on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂ Thanks you.
@harshit_pareek
6 ай бұрын
why you are completing all dsa series one by one😂
@harshmaurya7639
Ай бұрын
@@harshit_pareek 🤣🤣i always see his comnents in alternate videos
thanks and done
thanks sir
Attendance marked ✔️
Thanks sir
Present Bhaiya
Op bhaiya ♥️♥️
Attendance marked bhaiya🙏👍
nice bhaiya👍
Bhaiya moj kr dii
Time Complexity bhi improve hui thi bhaiya Kth subarray sum mein kyonki sum wali array ko sort karne ke liye (n^2)*log n time lag raha tha aur is heap wale tarike mein hamne sirf n^2 mein kar diya
Understood
Consistency op❤️
Thank you bhaiya I was just wondering ki kab aaega 😅😅
This lecture was very easy to understand. Well explained.
present bhaiya
In Ques . 1 : why we inserted only first (k-1) element in the heap , we insert k element in the heap then process the heap for rest of the elements and then our ans is heap.top( ) ... pls explain
best best best!
Please add subtitles it is so much more helpful for South Indians when you are explaining
after doing second problem, the last one was toooo easy
Bhaiya ❤️
T C of q1 using min heap is O(n^2 logk)
maza aagya
1st qs. Time complexity will be O(N^2. logN), N^2 for using 2 loops and log n for inserting / deleting values to/from minHeap .
@YashG2309
11 ай бұрын
O(N^2 log(K))
@inter3988
2 ай бұрын
study before comment
❤
Thanks ++
#BELIEVEINBABBAR I saw that gonna be green screen from next videos QUALITY++
Present bro
I have did like this, I have taken one answer list and Once i add any node to answer list, I am freeing that node from original lists. At the end i will be having answerlist in my hand after deleting the original lists. Which means i am using O(k) for priority queue, O(n*k) for answerlist but i am deleting original list which is of O(n*k). so final space is O(n*k) + O(k) - O(n*k) = O(k). Is this right way to do??
Bhaiya present !!
We need Handwritten Notes rest of Lectures, It's really time savings. When we have to revise, then I think all of us use that beautiful Notes. Otherwise it again a long time to see video again.
@motivationshorts3721
2 жыл бұрын
+1
@lostexplorer7442
2 жыл бұрын
Kuch khud bhi karlo!!
🎉🎉
🙏🙏🙏
🔥🔥🔥
Consistency is the key of success 😊
@lalitk
Жыл бұрын
Yes
Good
Need the code links to be updated bhaiya , it was a cherry on the top
completed
🔥
🔥🔥🔥🔥
🔥👌
Lecture 76: Heaps in C++ || Interview Questions || Part - 2
in this question you asked to sort the array, in such case can we use the sort method provided by java or we need to use the trivial looping method for sorting
@adamyasharma_0135
6 ай бұрын
sort method
concept+++