0

Insertion sort requires insertion of an element in sorted order by shifting the elements of an already sorted list while implemented through array. If instead of using arrays, we use doubly linked-list, what would be the time complexity?

Time Complexity Comes out to be O(n^2)? Why? If we consider insertion for n elements then it will be log(1) + log(2) + log(3) + ..... + log(n) - n times for n elements hence complexity should be O(nlogn)

Kara
6,23616 gold badges54 silver badges58 bronze badges
asked Apr 5, 2012 at 8:40
2
  • What makes you think it's log(1) + log(2) + ... + log(n) and not 1 + 2 + ... + n ? Please add more details in the questions, so you will get better more informative answers - which will be more likely to explain where your mistake is. Commented Apr 5, 2012 at 8:42
  • for insertion using insertion sort if we use doubly linked list then insertion of an element takes log(k) time where k is the number of already sorted elements Commented Apr 5, 2012 at 8:47

1 Answer 1

2

Insertion into a linked list takes time O(n), not O(lg n), because you have to navigate the link structure to find the insertion point.

answered Apr 5, 2012 at 8:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.