Time Complexity for Insertion Sort on Ref. Based Linked-List? -
here actual question:
"what time complexity if insertion sort done on reference-based linked list?"
i thinking o(1), right? because check nodes until find previous, , should node after, set pointers, , you're good. therefore, not every node need checked can't o(n).
big o notation refers worst case complexity.
inserting sorted list (which think how understanding question based on final paragraph) have complexity of o(n), since worst case inserting element goes @ end of list, meaning there n iterations.
performing insertion sort on unsorted linked list involve inserting n elements linked list, giving complexity of o(n^2).
Comments
Post a Comment