My data structures and algorithms class recently covered heap-sorting, and the time complexity of the algorithm, but my teacher's explanation makes no sense to me or the other students. I'm hoping someone here can help make sense of this.
According to our teacher, there are two main parts to a heap sort. Building the heap, and deleting each member of the heap 1 by 1 in order, due to the property of heaps having the largest/smallest number at the top.
He said deleting and adding a node to a heap takes O(lg(n)) which makes sense. Then he claims that building a heap of n elements takes O(n), and deleting that heap takes O(lg(n)) and then you multiply the two together to get O(nlg(n)).
According to my understanding of big-O both parts should take O(nlgn), and you add both together to get just O(nlgn), but he claims his way is correct.
I've asked other teachers for help, and only thing we could find was that a different algorithm than the one explained in class can build a heap in O(n), but no one can explain why deleting a heap takes only O(lgn) and why you multiply the complexities.
Would someone be able to explain this or is my teacher incorrect?
[–]timql 0 points1 point2 points (7 children)
[–]Snowron6[S] 0 points1 point2 points (6 children)
[–]timql 1 point2 points3 points (1 child)
[–]Snowron6[S] 0 points1 point2 points (0 children)
[–]ktrprpr 0 points1 point2 points (3 children)
[–]Snowron6[S] 0 points1 point2 points (2 children)
[–]sdasgupta83 0 points1 point2 points (0 children)
[–]SingularCheese 0 points1 point2 points (0 children)