I have a list of some objects and I want to iterate over them in a specific sequence for a specific number returned by the next function. Which does the following: removes each number based on the hash number module by the size of the list 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
For example: genSeq (53.5) will return [3, 1, 4, 2, 0]
I introduce algo in python for easy understanding. I have to write C ++ code. The complexity in this form is in O (n ^ 2) for both the vector and the list. (we either pay for deletion or for access). Can this be done better?
balki source share