1

Given the two data structures, Array and tuple, which is more complex, creating a new tuple or indexing and assigning a number to a particular index in an array.

For example, given the tuple/array containing x, y.

(0,0),[0,0]

If you want to change the two x, y values, is it quicker to create a new tuple or to index and assign to the array?

(0,1), [0, 1]

does the most efficient data structure change with the length?

LuckyPants
  • 123
  • 1
  • 9
  • 2
    Creating a new tuple is a more expensive operation than updating an element in a list. See here for details: https://wiki.python.org/moin/TimeComplexity – Jonas Jun 06 '18 at 04:20
  • 3
    That is a *list* not an array. Creating a new tuple is linear on the size of a tuple (time and space). Mutating an element of a *list* is a constant time operation. But if you are always going to mutate every element in a list, that is also linear time (although constant space). – juanpa.arrivillaga Jun 06 '18 at 04:20
  • 1
    Related: https://stackoverflow.com/questions/626759/whats-the-difference-between-lists-and-tuples?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – juanpa.arrivillaga Jun 06 '18 at 04:23

0 Answers0