Arrays and Lists Flashcards
What is an implementation of a shuffle algorithm?
This is an implementation of the Inside-Out variation of the Fisher-Yates shuffle:
To initialize an array a of n elements to a randomly shuffled copy of “source”, both 0-based
for i from 0 to n - 1 do:
j = random integer such that 0 <= j <= i
if j != i, then a[i] = a[j]
a[j] = source[i]
Time complexity of python list copy
O(n)
Time complexity of python list append[1]
O(1)
Time complexity of python list insert
O(n)
Time complexity of python list get item
O(1)
Time complexity of python list set item
O(1)
Time complexity of python list delete item
O(n)
Time complexity of python list get slice[k]
O(k)
Time complexity of python list del slice
O(n)
Time complexity of python list set slice[k]
O(k+n)
Time complexity of python list extend
O(k)
Time complexity of python list sort
O(n log n)
Time complexity of python list multiply []*k
O(nk)
Time complexity of python list x in s
O(n)
Time complexity of python list min/max
O(n)