Given an algorithm, do worst case time complexity "class" vary with array and linked list?

My intuition says that I can make a sorting algorithm(may be a strange, not an useful), such that with array it have different worst case time complexity class and linked list(assuming time complexity of operation performed in linked list are same as conventionally used) with different complexity class.
But what about the sorting algorithms which are conventionally used(may be the algorithms in CLRS)?
I am assuming the implementation done on RAM model and by class I mean the set $\theta(f)$ with f as worst case running time of the algorithm

• Have you thought about what happens when you implement quick sort or merge sort for linked lists? Sep 17, 2016 at 14:15
• @adrianN Yeah practically it does make different, but what about complexity class? quick sort is in $\theta (nˆ{2})$ in both and merge sort in $\theta(nlog(n))$ in both(worst case) Sep 17, 2016 at 15:06
• I'd argue that you can implement both sorting algorithms for linked lists with the same asymptotic bounds. I suggest you try to figure out how, it shouldn't be terribly difficult. Sep 17, 2016 at 15:08
• yeah sure, but what about other algorithms ? Is that true for all other Sep 17, 2016 at 15:12
• No, for example the algorithm that takes a list (or an array) and a number $k$ and returns the $k$-th element has a different runtime. Sep 17, 2016 at 15:20

1 Answer

Note that complexity classes are classes of problems, not classes of algorithms. Specifically, complexity classes are classes of problems that can be solved within particular resource bounds by some algorithm. So, for example, sorting is in polynomial time because there is at least one algorithm that sorts with this resource bound. (In fact, you probably know many algorithms that do this.)

When it comes to comparing different algorithms for solving the same problem, yes, they may have different resource usage. The fact that you have random access to the elements of an array but not to a linked list means that you can probably design more efficient algorithms based on arrays compared to those based on linked lists. And note that, by using different data structures, they are different algorithms: they involve different computational steps.

Note also that all of this is dependent on your model of computation. For example, if you're solving computational problems using Turing machines, then arrays and linked lists are essentially the same thing, because we can only access the array by moving the tape head sequentially through the elements. Typically, though, when analyzing actual algorithms, we use models of computation, such as the random access Turing machine, that correspond more closely to actual computers.

• May be, I might not have used technically correct terms, but My question is do they both(one for array and one for linked list) lie in the same $\theta(f)$(by class I meant this set) for some function f(using RAM model)?<br> I think now my question is precise Sep 18, 2016 at 4:54
• @saravanan I answer that in the second paragraph. Sep 18, 2016 at 8:18