Table of Contents: Plugging The Channel 0:00 - 0:36 The Problem Introduction 0:36 - 1:13 A Heap Is Not An ADT 1:13 - 1:43 The ADT Priority Queue 1:43 - 3:39 The Min and Max Heap 3:39 - 5:50 Insertions & Removals On A Min Heap 5:50 - 8:57 Our First Removal 8:57 - 11:16 Continue Insertions 11:16 - 13:20 Our Second Removal 13:20 - 15:21 Our Third Removal 15:21 - 15:54 Continue Insertions 15:54 - 17:47 Notice Our Heaps Contents 17:47 - 18:32 Time Complexity For Insertion & Removal 18:32 - 19:35 Wrap Up 19:35 - 20:00 The code is in the description fully commented for teaching purposes.
@@Rhythmswithruby public class Solution { /* A min heap implementation Array Form: [ 5, 7, 6, 10, 15, 17, 12 ] Complete Binary Tree Form: 5 / \ 7 6 / \ / \ 10 15 17 12 Mappings: Parent -> (childIndex - 1) / 2 Left Child -> 2 * parentIndex + 1 Right Child -> 2 * parentIndex + 2 */ private static class MinHeap { private int capacity = 5; private int heap[]; private int size; public MinHeap() { heap = new int[capacity]; } public boolean isEmpty() { return size == 0; } public int peek() { if (isEmpty()) { throw new NoSuchElementException("Heap is empty."); } return heap[0]; } public int remove() { if (isEmpty()) { throw new NoSuchElementException("Heap is empty."); } /* -> Grab the min item. It is at index 0. -> Move the last item in the heap to the "top" of the heap at index 0. -> Reduce size. */ int minItem = heap[0]; heap[0] = heap[size - 1]; size--; /* Restore the heap since it is very likely messed up now by bubbling down the element we swapped up to index 0 */ heapifyDown(); return minItem; } public void add(int itemToAdd) { ensureExtraCapacity(); /* -> Place the item at the bottom, far right, of the conceptual binary heap structure -> Increment size */ heap[size] = itemToAdd; size++; /* Restore the heap since it is very likely messed up now by bubbling up the element we just put in the last empty position of the conceptual complete binary tree */ siftUp(); } /*********************************** Heap restoration helpers ***********************************/ private void heapifyDown() { /* We will bubble down the item just swapped to the "top" of the heap after a removal operation to restore the heap */ int index = 0; /* Since a binary heap is a complete binary tree, if we have no left child then we have no right child. So we continue to bubble down as long as there is a left child. A non-existent left child immediately tells us that a right child does not exist. */ while (hasLeftChild(index)) { /* By default assume that left child is smaller. If a right child exists see if it can overtake the left child by being smaller */ int smallerChildIndex = getLeftChildIndex(index); if (hasRightChild(index) && rightChild(index) < leftChild(index)) { smallerChildIndex = getRightChildIndex(index); } /* If the item we are sitting on is < the smaller child then nothing needs to happen & sifting down is finished. But if the smaller child is smaller than the node we are holding, we should swap and continue sifting down. */ if (heap[index] < heap[smallerChildIndex]) { break; } else { swap(index, smallerChildIndex); } // Move to the node we just swapped down index = smallerChildIndex; } } // Bubble up the item we inserted at the "end" of the heap private void siftUp() { /* We will bubble up the item just inserted into to the "bottom" of the heap after an insert operation. It will be at the last index so index 'size' - 1 */ int index = size - 1; /* While the item has a parent and the item beats its parent in smallness, bubble this item up. */ while (hasParent(index) && heap[index] < parent(index)) { swap(getParentIndex(index), index); index = getParentIndex(index); } } /************************************************ Helpers to access our array easily, perform rudimentary operations, and manipulate capacity ************************************************/ private void swap(int indexOne, int indexTwo) { int temp = heap[indexOne]; heap[indexOne] = heap[indexTwo]; heap[indexTwo] = temp; } // If heap is full then double capacity private void ensureExtraCapacity() { if (size == capacity) { heap = Arrays.copyOf(heap, capacity * 2); capacity *= 2; } } private int getLeftChildIndex(int parentIndex) { return 2 * parentIndex + 1; } private int getRightChildIndex(int parentIndex) { return 2 * parentIndex + 2; } private int getParentIndex(int childIndex) { return (childIndex - 1) / 2; } private boolean hasLeftChild(int index) { return getLeftChildIndex(index) < size; } private boolean hasRightChild(int index) { return getRightChildIndex(index) < size; } private boolean hasParent(int index) { return index != 0 && getParentIndex(index) >= 0; } private int leftChild(int index) { return heap[getLeftChildIndex(index)]; } private int rightChild(int index) { return heap[getRightChildIndex(index)]; } private int parent(int index) { return heap[getParentIndex(index)]; } } }
@@BackToBackSWE hey have one question. What would be time complexity (both iterative and recursive) for verifying/building a general K-ary max heap (not just binary but for ternary and so forth)?
i really appreciate the fact you edit out the insane amount of erasing and rewriting youre doing in all of these. each of these videos must take so long to record and edit O_O thanks mate
I admire your dedication and treasure it a lot! It is an honour to have someone as skilled as you taking the time to explain these concepts for beginners like us!!!
2 minutes into the video, this guy answered questions I had to ask my professors for weeks to understand. You might not understand everything he is saying, but this is the same stuff that I'm being taught at a private, super expensive, well ranked engineering school. Thanks for the help!
Happy Holidays 🎉 Thank you for your kind words, MarkRosenthal! We'd love to offer you a 40% Off our exclusive lifetime membership just use the code CHEER40 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=CHEER40
Omg, this video was posted 5 years back and is still the best video I've ever seen. Your explanation makes it so simple! Glad I found your channel.. it's a gem 💎❤
Hello Sir!!! I am from Myanmar student who is learning Software Engineering. Your videos are so effective for me and you can explain very clearly. Thanks for sharing your knowledge.
I like how he asks the question 'Do you see xxxx ?'. It just gives me a feeling that I'm actually sitting in front of him, and it makes me more engaged into the video.
This is literally a legendary video lol. I am learning BST and Heap in my data strucutres class and i understand majority of the BST stuff, but the heap was like, easy to understand but weird as hell to understand that its no longer an ADT etc. You did a great job explaining all this.
I had an onsite question that involved heaps... I didn't get the offer, and went on a berserk mode to understand where I went wrong. Your explanation is the clearest one I've seen. Thank you.
legit one of the best channels on youtube. these are beautiful and my go-to interview studying (and my last-minute nerves studying). thank you for the wonderful content!
this channel is the reason i'll pass my data structures class )': thanks so much man please keep making these videos!! you really explain stuff so in-depth.
Man . you are just the best . you are just doing something that a lot of people will appreciate you . your contexts are just perfect . I can't find tutorials about DS&ALG better than this channel . I just don't understand your pause at the end of Videos :|)
This man smokes tricky concepts like it aint no thing! @B2BSWE, I like how you explain the concepts and don't just immediately jump into optimized code. I've seen videos like that before, where I guess the goal is to memorize a process and I walk away feeling unsure about what I "learned".
thank you so much. actually i have implemented priority queue through linked list but then my prof said i have to implement through heaps. This is a very confusing topic but you actually made it so easy and understandable. ❤🌹
Just found your channel, and smashed that subscribe button. Thank you so much for your content! It helps me and my GPA a lot. Also, I can see your channel becoming the world's biggest resource of SWE in the future. Will support you through it all.
Man this vid is so rad! This is the best explanation I've seen yet. I've always wanted to implement compression with huffman coding and now this is is very clear. I never bothered to learn what log n complexity meant (altho I'm supposed to be a a dev) but now this is obvious. Like if you double the size of the elements in the binary tree you only have to go one step further to bubble up or down one element by comparing and swaping with parents/children hence it's log since it depends of the exponent value. Thank's.
18:31 complexity of removal and instertion (under the premise that we are maintaining the min-heap). The key idea is that the height of the tree is log_2(n) where n is the length of the data.
Absolutely amazing and thorough. Beautiful breakdown. Best explanation I have seen yet and could not have been better. Will check out your products and really hope your full courses and career services come in time for upcoming graduation and recruitment!
hey , i think you could have added one more part to video, that is how can we use array to store heap, and that can also make anyone understand how it is even possible to get last element from tree, and how to even know which one is parent of node. But yeah, explanation was just awesomeeee.
You can retrieve the min and max in both a min-heap and max-heap in constant time. They are always the first index and the (heap.size - 1) index of the heap
So, when you say it takes constant time - O(1) to do peek of the heap, does it mean the caller of the heap does not care about the heap restoration operations. I am assuming the heap restoration operations happens asynchronously in the background. Am I correct on this one?
i think there is a mistake at first removal around 8:58. Instead of selecting the minimum child, the max child was selected for replacement of parent node. This was corrected later in the video
Thank you, We have complete course on our platform 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
At 13:22, I think 0, (next row) 10, 20, (next row), 15, 30, but 15 is where I get confused since shouldn't the number in 15's place be larger than 20? I thought each number increases as you go from left to right, then down to the next row below, keeps increasing.
Another game changer video. I had a question about Abstract Data Types vs Data Structures. I am confused how a heap is not an Abstract Data Type since when we insert or remove from the heap we are adding (behavior) to the heap and it makes me think of it as an Abstract Data type (values and set of operations on these values). I know I am looking at this incorrectly but any clarity would be appreciated 🤙
Table of Contents:
Plugging The Channel 0:00 - 0:36
The Problem Introduction 0:36 - 1:13
A Heap Is Not An ADT 1:13 - 1:43
The ADT Priority Queue 1:43 - 3:39
The Min and Max Heap 3:39 - 5:50
Insertions & Removals On A Min Heap 5:50 - 8:57
Our First Removal 8:57 - 11:16
Continue Insertions 11:16 - 13:20
Our Second Removal 13:20 - 15:21
Our Third Removal 15:21 - 15:54
Continue Insertions 15:54 - 17:47
Notice Our Heaps Contents 17:47 - 18:32
Time Complexity For Insertion & Removal 18:32 - 19:35
Wrap Up 19:35 - 20:00
The code is in the description fully commented for teaching purposes.
I don't see the code in the description or a link to it. Am I blind or is it gone?
The repository is deprecated - we only maintain backtobackswe.com now
@@BackToBackSWE So it's not free anymore?
where can i find c++ code... and I don't find any code in description
@@Rhythmswithruby public class Solution {
/*
A min heap implementation
Array Form: [ 5, 7, 6, 10, 15, 17, 12 ]
Complete Binary Tree Form:
5
/ \
7 6
/ \ / \
10 15 17 12
Mappings:
Parent -> (childIndex - 1) / 2
Left Child -> 2 * parentIndex + 1
Right Child -> 2 * parentIndex + 2
*/
private static class MinHeap {
private int capacity = 5;
private int heap[];
private int size;
public MinHeap() {
heap = new int[capacity];
}
public boolean isEmpty() {
return size == 0;
}
public int peek() {
if (isEmpty()) {
throw new NoSuchElementException("Heap is empty.");
}
return heap[0];
}
public int remove() {
if (isEmpty()) {
throw new NoSuchElementException("Heap is empty.");
}
/*
-> Grab the min item. It is at index 0.
-> Move the last item in the heap to the "top" of the
heap at index 0.
-> Reduce size.
*/
int minItem = heap[0];
heap[0] = heap[size - 1];
size--;
/*
Restore the heap since it is very likely messed up now
by bubbling down the element we swapped up to index 0
*/
heapifyDown();
return minItem;
}
public void add(int itemToAdd) {
ensureExtraCapacity();
/*
-> Place the item at the bottom, far right, of the
conceptual binary heap structure
-> Increment size
*/
heap[size] = itemToAdd;
size++;
/*
Restore the heap since it is very likely messed up now
by bubbling up the element we just put in the last empty
position of the conceptual complete binary tree
*/
siftUp();
}
/***********************************
Heap restoration helpers
***********************************/
private void heapifyDown() {
/*
We will bubble down the item just swapped to the "top" of the heap
after a removal operation to restore the heap
*/
int index = 0;
/*
Since a binary heap is a complete binary tree, if we have no left child
then we have no right child. So we continue to bubble down as long as
there is a left child.
A non-existent left child immediately tells us that a right child does
not exist.
*/
while (hasLeftChild(index)) {
/*
By default assume that left child is smaller. If a right
child exists see if it can overtake the left child by
being smaller
*/
int smallerChildIndex = getLeftChildIndex(index);
if (hasRightChild(index) && rightChild(index) < leftChild(index)) {
smallerChildIndex = getRightChildIndex(index);
}
/*
If the item we are sitting on is < the smaller child then
nothing needs to happen & sifting down is finished.
But if the smaller child is smaller than the node we are
holding, we should swap and continue sifting down.
*/
if (heap[index] < heap[smallerChildIndex]) {
break;
} else {
swap(index, smallerChildIndex);
}
// Move to the node we just swapped down
index = smallerChildIndex;
}
}
// Bubble up the item we inserted at the "end" of the heap
private void siftUp() {
/*
We will bubble up the item just inserted into to the "bottom"
of the heap after an insert operation. It will be at the last index
so index 'size' - 1
*/
int index = size - 1;
/*
While the item has a parent and the item beats its parent in
smallness, bubble this item up.
*/
while (hasParent(index) && heap[index] < parent(index)) {
swap(getParentIndex(index), index);
index = getParentIndex(index);
}
}
/************************************************
Helpers to access our array easily, perform
rudimentary operations, and manipulate capacity
************************************************/
private void swap(int indexOne, int indexTwo) {
int temp = heap[indexOne];
heap[indexOne] = heap[indexTwo];
heap[indexTwo] = temp;
}
// If heap is full then double capacity
private void ensureExtraCapacity() {
if (size == capacity) {
heap = Arrays.copyOf(heap, capacity * 2);
capacity *= 2;
}
}
private int getLeftChildIndex(int parentIndex) {
return 2 * parentIndex + 1;
}
private int getRightChildIndex(int parentIndex) {
return 2 * parentIndex + 2;
}
private int getParentIndex(int childIndex) {
return (childIndex - 1) / 2;
}
private boolean hasLeftChild(int index) {
return getLeftChildIndex(index) < size;
}
private boolean hasRightChild(int index) {
return getRightChildIndex(index) < size;
}
private boolean hasParent(int index) {
return index != 0 && getParentIndex(index) >= 0;
}
private int leftChild(int index) {
return heap[getLeftChildIndex(index)];
}
private int rightChild(int index) {
return heap[getRightChildIndex(index)];
}
private int parent(int index) {
return heap[getParentIndex(index)];
}
}
}
This man explains better than my prof who has a PhD in Comp Sci lmao One of the best channels to understand Data Structures!
hey
@@BackToBackSWE hey have one question. What would be time complexity (both iterative and recursive) for verifying/building a general K-ary max heap (not just binary but for ternary and so forth)?
If not the best
well, you do realise you are visiting this topic not the first time?
Well getting a PhD doesn't really correlate with how well you can explain a simple-data structure
i really appreciate the fact you edit out the insane amount of erasing and rewriting youre doing in all of these. each of these videos must take so long to record and edit O_O thanks mate
hahahahhaha, thanks for noticing the details. Yeah each video takes from 4-6 hours from shooting to editing.
I admire your dedication and treasure it a lot! It is an honour to have someone as skilled as you taking the time to explain these concepts for beginners like us!!!
haha im not that skilled
This channel is by far the best at breaking down and explaining DSA concepts that I've ever seen (including university). Thanks for your awesome work!
sure
2 minutes into the video, this guy answered questions I had to ask my professors for weeks to understand. You might not understand everything he is saying, but this is the same stuff that I'm being taught at a private, super expensive, well ranked engineering school. Thanks for the help!
Happy Holidays 🎉 Thank you for your kind words, MarkRosenthal! We'd love to offer you a 40% Off our exclusive lifetime membership just use the code CHEER40 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=CHEER40
The way he explains, just goes into the mind..
ye
One of the best explanations I've seen for this topic, is complete, clear, with graphics, and examples. Thank you so much.
Omg, this video was posted 5 years back and is still the best video I've ever seen. Your explanation makes it so simple! Glad I found your channel.. it's a gem 💎❤
This is "THE BEST CHANNEL" for SWE..... Love it
Hello Sir!!!
I am from Myanmar student who is learning Software Engineering.
Your videos are so effective for me and you can explain very clearly.
Thanks for sharing your knowledge.
Sure
Simplicity is quality of this channel.
you are an increadible human being for puttin this content out there.
literally you explain better than any teacher I've ever had, keep it up, greetings from Colombia
I like how he asks the question 'Do you see xxxx ?'. It just gives me a feeling that I'm actually sitting in front of him, and it makes me more engaged into the video.
This is literally a legendary video lol. I am learning BST and Heap in my data strucutres class and i understand majority of the BST stuff, but the heap was like, easy to understand but weird as hell to understand that its no longer an ADT etc. You did a great job explaining all this.
nice
I had an onsite question that involved heaps... I didn't get the offer, and went on a berserk mode to understand where I went wrong. Your explanation is the clearest one I've seen. Thank you.
sure
youtube takes time but is rewarding, keep the tempo going
lol ok
legit one of the best channels on youtube. these are beautiful and my go-to interview studying (and my last-minute nerves studying). thank you for the wonderful content!
thanks wish u the best!
The best explanation of heap I could found. Short and clear
Hands down to THE BEST CHANNEL
ye
this channel is the reason i'll pass my data structures class )': thanks so much man please keep making these videos!! you really explain stuff so in-depth.
Nice, sure, workin' on it
You are a legend. This channel is awesome for quick review and for first attempts. Thanks for all the forethought and effort put into your videos.
thx - wish u the best
Very helpful! I feel like I’m in an actual lecture, but with an awesome instructor. Thanks for the video!
thanks and thanks
one of the best ds channels..great work
thanks thanks
Thank you for the awesome explanation. Looking forward to more of your tutorial videos
sure
My n word I suscribed the moment you said you want this to be the biggest resource for SE online. I wish you the best of luck.
lmao, comment of the year
Man . you are just the best . you are just doing something that a lot of people will appreciate you . your contexts are just perfect . I can't find tutorials about DS&ALG better than this channel .
I just don't understand your pause at the end of Videos :|)
This man smokes tricky concepts like it aint no thing! @B2BSWE, I like how you explain the concepts and don't just immediately jump into optimized code. I've seen videos like that before, where I guess the goal is to memorize a process and I walk away feeling unsure about what I "learned".
I got u, thx 4 watching
Absolutely love the explanations of the fundamental building blocks of the more complex stuff! Much gratitude.
Best explanation of heaps I've seen on here..thanks dude..so easy to follow.
sure.
Your videos are by far the best. Keep up the good work!
thanks
thank you so much. actually i have implemented priority queue through linked list but then my prof said i have to implement through heaps. This is a very confusing topic but you actually made it so easy and understandable. ❤🌹
great
Love your enthusiasm in this tutorial!
nobody:
ben: "we're missing one child, that's fine"
lol
First video of yours that I've seen. Excited to check out more. Thanks for the info!
Glad to hear that! Subscribe to our DSA course for some amazing content with a flat 30% discount b2bswe.co/3HhvIlV
You deserve a medal for all the work you do! and the best part you always reply to my comments! Keep enlightening us with your videos!😊😊
Thanks and no I don't, I had/have a mission and it has nothing to do with me. And yeah, I reply to everyone. And sure.
I’ve been looking for an instructor like you since i first started studying computer science almost seven years ago
Glad to hear that!
Subscribe to our DSA course with a flat 30% discount for some amazing content b2bswe.co/3HhvIlV
quality videos bro, I not only learn but I enjoy watching them too
Just found your channel, and smashed that subscribe button. Thank you so much for your content! It helps me and my GPA a lot.
Also, I can see your channel becoming the world's biggest resource of SWE in the future. Will support you through it all.
hey
Please add captions...I'm taking notes of this concise and precise video, indeed a precious video. Thank you
thanks and ok
Helped me implement this in minutes thanks to the video.
great
Man you don't know how much of a help you are for us! You always help me through, thank you so much you are the best.
Dude I swear you are the one making me pass my algo lecture! Your vids are helping me so much with every exercise
This video explains the remove so well.
bro, U R soooo way better than my instructor
thx - you instructor is probably giving an effort though
@@BackToBackSWE yes ofcourse, he is trying his best but still you are kinda better
Man this vid is so rad! This is the best explanation I've seen yet. I've always wanted to implement compression with huffman coding and now this is is very clear. I never bothered to learn what log n complexity meant (altho I'm supposed to be a a dev) but now this is obvious. Like if you double the size of the elements in the binary tree you only have to go one step further to bubble up or down one element by comparing and swaping with parents/children hence it's log since it depends of the exponent value. Thank's.
thanks
Thanks. Short and sweet review for my exam.
18:31 complexity of removal and instertion (under the premise that we are maintaining the min-heap). The key idea is that the height of the tree is log_2(n) where n is the length of the data.
Interviewer: 'Heap'
Me: 'parent am I smaller than you' 😋
Interviewer: ....
P.S: thanks for these awesome videos!
hi
Absolutely amazing and thorough. Beautiful breakdown. Best explanation I have seen yet and could not have been better. Will check out your products and really hope your full courses and career services come in time for upcoming graduation and recruitment!
ye
9:44 heapify, such a cool word, I'm gona start using it
lol, I don't think it is a real word
@@BackToBackSWE in python standard library: heapq.heapify(x) is a thing. :)
@@neurochannels nice
Yeah...something out of a spell from Harry Potter
hey , i think you could have added one more part to video, that is how can we use array to store heap, and that can also make anyone understand how it is even possible to get last element from tree, and how to even know which one is parent of node.
But yeah, explanation was just awesomeeee.
thanks and ok
DUDE you are killin it, thank you.
I'm fine and thanks
I’m becoming a fan of yours...
very nice explanation
no im a fan of u
Best Explanation on Internet :)
thx
The best explanation ever!
This dude is a straight boss I love your videos man 👍
Thanks Terry
You are great teacher, what a clear explanation of each topic. Please post more learning videos of popular algorithms
thanks and ok
You can retrieve the min and max in both a min-heap and max-heap in constant time. They are always the first index and the (heap.size - 1) index of the heap
So, when you say it takes constant time - O(1) to do peek of the heap, does it mean the caller of the heap does not care about the heap restoration operations. I am assuming the heap restoration operations happens asynchronously in the background. Am I correct on this one?
You are so amazing... I think I'm best lucky for choosing this video tutorial among many others....
Glad I found your channel
Best videos on data structure. Already said that, will say it again!!
thank you!
Thank you so much for your videos that make algorithm so much easier to understand! Looking forward to more of them:)
sure
i think there is a mistake at first removal around 8:58. Instead of selecting the minimum child, the max child was selected for replacement of parent node. This was corrected later in the video
I have to applaud you for this! Thank you, thank you! I love how u put it in Layman's term
Excellent video buddy really solidified the concept of a binary heap for me
sure
OMG you explain so clear! Thanks!
This man knows his shit.
lol
You should really make complete courses you are so great
Thank you, We have complete course on our platform 😀
Do check out backtobackswe.com/platform/content
and please recommend us to your family and friends 😀
Hi, really great video, thanks! I don’t see the code in the description, am I missing something?
Thanks John
sure
very clear explanation & examples
thanks null
The explanation is perfect but It will be great if you also explain a clean code with the explanation. So that we don't have to search for the code.
thanks and the respository is deprecated - we only maintain backtobackswe.com now.
Great video, as always! Nice job!
hola
At 13:22, I think 0, (next row) 10, 20, (next row), 15, 30, but 15 is where I get confused since shouldn't the number in 15's place be larger than 20? I thought each number increases as you go from left to right, then down to the next row below, keeps increasing.
You are a hero dude, seriously saved my ass with this video
great to hear.
amazing brother - nice and simple - keep going, i'll be checking here first!
Thank you, glad you liked it 😀
Do check out backtobackswe.com/platform/content
and please recommend us to your family and friends 😀
As soon as I get a job I'll pay your course. Others courses that I paid didn't work for me :( Well at least I didn't spend too much $ back then.
No need. Just tell people about us.
Amazing explanation!
Thanks for the awesome explanation.
Another game changer video. I had a question about Abstract Data Types vs Data Structures. I am confused how a heap is not an Abstract Data Type since when we insert or remove from the heap we are adding (behavior) to the heap and it makes me think of it as an Abstract Data type (values and set of operations on these values). I know I am looking at this incorrectly but any clarity would be appreciated 🤙
Thanks. The ADT is priority queue and the heap is the data structure, see en.wikipedia.org/wiki/Priority_queue#Implementation
Thank you!!!!! You are so good, its hard not to recommend you
Thank you, glad you liked it 😀
Do check out backtobackswe.com/platform/content
and please recommend us to your family and friends 😀
Great videos! Where can I find the solution? Looks like the code link is missing?
In order to insert and keep tree complete/balanced, seems like we need to use breadth first search, and find first node without a right child?
No breadth first search, the heap will be encoded into an array. View the heap sort video.
you are an excellent teacher! thankyou!!
You’re an awesome teacher!
full program in c++ for max heap and heap sort
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct node
{
int data;
node* left;
node* right;
node* prev;
};
class max_heap
{
private:
int first=1;
node* rroot;
node* act;
node* last;
queue q1;
stack stack1;
void traverse11(node *ptr , int x=0)
{
if(ptr!=NULL)
{
coutprev=temp1;
q1.push(new1);
q1.push(new1);
check(new1);
}else if(temp1->right==NULL)
{
temp1->right=new1;
new1->prev=temp1;
q1.push(new1);
q1.push(new1);
check(new1);
}
}
}
int peek()
{
return rroot->data;
}
void pop()
{
node *last=stack1.top();
act=last->prev;
if(stack1.size()==1)
{
cout
Thanks! 🧡🧡
Thank you, glad you liked it 😀
Do check out backtobackswe.com/platform/content
and please recommend us to your family and friends 😀
Please do more on Dynamic Programming. Please. You are God. Please.
I am normal
helps a lot when im preparing for final thx!
sure
thnq so much man. it helped me a lot.Excellent explanation
I'm impress what a great explanation!
Glad it was helpful
Love from India
nice - hey
you just saved my semester
I don't see the code in the description, maybe I might be missing something?
very detailed explaination
great explanation! thanks!
sure
I love this music at the end