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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -