Query Regarding Priority Queue & Sorting

If We have an unsorted array, we put it inside priority
queue,after that one by one pop all queue elements and store in an
array, it will be sorted.

Although I didn’t use sorting but data gets sorted.

Inbuilt sort runs in O(nlogn) but Heap priority queue will do it in
O(n) or O(logn).

So, can we always use priority queue whenever I Need sorting? If we
ignore Space Complexity Though.

@rtg67GHu_67 that time complexity is for 1 element, but in an array n elements will be present. When we do these operations for n elements, the time complexity becomes nlogn, along with the O(n) space complexity.

1 Like

Ohhh I Forgot That by Mistake, Thanks

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.