way better than my current DS class... thx professor Edward ! !
@belwizdadimed39675 жыл бұрын
Clear explanation but you should have used just an int[] array to avoid littering the code with generics comparable and hide the essential topic.
@Croccifixo5 жыл бұрын
Isn't there a problem with the second if-statement? Consider the situation where right is indeed the last position, meaning there must also be a left child. If the right position is greater than parent, you always swap it, regardless of whether the left child is greater than right. In the case that the right child is last position, you should consider it as an internal node. Also, using greater than or equal to in the third if-statement is redundant, as you have already checked for equality, simply using strictly greater than is more accurate (and you will not need to check right, if a node doesn't have a left child, it wont have a right child, if it only has a left child, this is handled in the first if statement, and if it has both, it's an internal node). I would consider removing the second if statement and updating the condition of the third one to if (left > lastPosition)
@alexandercheprasov90484 жыл бұрын
Yep. I had the same comments when was watching it :)
@animeshkumar95934 жыл бұрын
Glad I found this comment. I was thinking the same while watching the video
@teetanrobotics53635 жыл бұрын
Please make a playlist for algorithm design and analysis.
@Play-Date-Care4 жыл бұрын
We always remove root, then trickle down, but what if the value we want to remove is not in the root, is some other node?
@lewisben66975 жыл бұрын
In the third case in TrickDown function, there should be no equal because the first two cases had discussed about it
@1Maestr00o35 жыл бұрын
wouldn't the second if statement be better like this: if(right == lastPosititon && array[parent] < array[right] && array[left] < array[right]){ swap(parent, right); return; }else if(right == lastPosititon && array[left] > array[parent]){ swap(parent, left); return; } ?
@monickverma29444 жыл бұрын
it's same
@ahmidahmid93035 жыл бұрын
the remove is complicated function
@kubuspat97295 жыл бұрын
Tell me, what about the statement where the parent is bigger than his childs. Where is statement for that case? // i answear that question for myself xD ( there won't be such a case )
@philspaghet6 жыл бұрын
Algorithm doesn't work, the if conditions make it exit loop early
@Play-Date-Care6 жыл бұрын
I'm thinking the same, would the recursive call happen inside of the if loop?
@potatorun35416 жыл бұрын
the return statement in if conditions is only reached when left or right as already at last position.
@Croccifixo5 жыл бұрын
@@potatorun3541 if right is last position, it might cause a heap violation, but that is only because of the second if-statement (consider adding a 17 as the last node in the video before trickleDown, the second if-statement will swap 17 and 11, causing 17 to be a parent to 22 and ending the recursion)