Building a heap by pushing each new value up to the root is essentially a sequence of insertions. Each insertion takes \(O(\log n)\) time, and we perform this for all \(n\) elements, resulting in a time complexity of \(O(n \log n)\). This is more efficient than other methods like sorting the array first, which would take \(O(n \log n)\) as well.
Was this answer helpful?
0
0
Top AP PGECET Computer Science & Information Technology Questions