educative.io

Time complexity for delete

In the quiz it gives the time complexity for delete as O(log n). But surely that only applies to deleting the min/max value because for deleting any node you would have to iterate the whole tree to find it?

Hi Hasan_Zaidi,

This is Arqam from Educative. We are really happy to hear from you.

Actually, the deletion of a random node would take O(n+log(n)), as first we find where the random element is in the heap, which will take O(n), and then delete it which will further take O(log(n)).

But here, we are talking about when the index of a node to be deleted is already given.
Our team has modified the description to avoid further confusions.

Thanks and Regards,
Arqam Rehan | Developer Advocate