I have a list of some objects and I want to iterate through them in a specific sequence for a particular number as returned by the following function. What the following does is, removes each number based on the modulo of the hash number to the list size and generates a sequence.
def genSeq(hash,n):
l = range(n)
seq = []
while l:
ind = hash % len(l)
seq.append(l[ind])
del l[ind]
return seq
Eg: genSeq(53,5) will return [3, 1, 4, 2, 0]
I am presenting the algo in python for easy understanding. I am supposed to code in c++. The complexity in this form in O(n^2) both for vector and list. (we either pay for removing or for access). Can this be made any better ?