I know that linked list is not a appropriate data structure for building heaps but I am interested in knowing the time complexity of building heaps and heapsort using linked list.
One of the answers here (https://stackoverflow.com/a/14584517/5841727) says that heap sort can be done in O(nlogn) using linked list which is same as with arrays.
For building a heap, I think that heapify operation would cost O(n) time in linked list and we would need (n/2) heapify operations leading to time complexity of O(n^2). Is it correct?
Also, can someone please tell how to achieve O(nlogn) complexity (for heap sort ) using linked list ?
1 Answer 1
doubly linked list can be sorted by heapsort with O(nlogn) time, O(1) space complexity, but not singly linked-list. merge sort can apply to singly linked list with O(nlogn) time, O(n) space complexity.
-
5$\begingroup$ This answer would be greatly improved by explanations of how this is done, why it can't be done for singly-linked lists and, ideally, giving some citations. $\endgroup$David Richerby– David Richerby2019年06月12日 09:03:00 +00:00Commented Jun 12, 2019 at 9:03
Explore related questions
See similar questions with these tags.
we would need (n/2) heapify operations
No. In heap-sort, heapify is used once, followed by more sifts in the opposite direction.. $\endgroup$