0

Heap sort can be implemented using linked list and arrays.

What would be the ideal method of doing it-using linked list or arrays?

What is the time complexity to build heap using arrays and linked lists?Is it O(nlogn) for both?

What is the time complexity for deletion?

1
  • This looks an assignment: Please give your take for each of the questions raised. Where different from "conventional wisdom", show your reasoning. Commented Jan 31, 2018 at 7:49

3 Answers 3

2

for array, it is O(nlogn). becoz u can easily fetch element at index i. this characteristic makes it easy to fetch each node's parent and left/right child. and the time complexity for deletion is O(lgn).

for linked list, i think it is a different story. it depends how u define the "next" node. as far as i know, it is more complex than using array.

Sign up to request clarification or add additional context in comments.

Comments

2

Binary Heap

Time complexity in big O notation

        Average        Worst case
Space   O(n)           O(n)
Search  N/A Operation  N/A Operation
Insert  O(log n)       O(log n)
Delete  O(log n)       O(log n)

So, Time complexity is the same independent of whether it is using linked lists arrays .

Comments

0

Time complexity is the same using either linked lists or arrays, assuming a proper implementation.

I have several implementations of heap sort at my blog. Start here for the traditional array-based version, then follow the links for several linked list versions.

1 Comment

(Posts shall contain enough information to stay useful even when (external) hyperlinks go stale.) The presentation of heapify is bad. I neither found a single linked list versions (not even an explicit hyperlink) nor a complexity analysis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.