Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time complexity of accessing an element in a tuple

There is similar question about hash (dictionaries) and lists, also there is a good piece of info here: http://wiki.python.org/moin/TimeComplexity

But I didn't find anything about tuples.

The access time for

data_structure[i]
  • for a linked list is in general O(n)
  • for dictionary is ~ O(1)

What about tuple? Is it O(n) like for a linked list or O(1) like for an array?

like image 738
Ivan Avatar asked May 27 '11 14:05

Ivan


1 Answers

It's O(1) for both list and tuple. They are both morally equivalent to an integer indexed array.

like image 159
David Heffernan Avatar answered Sep 23 '22 06:09

David Heffernan