Thursday, 15 September 2011

python - O(nlogn) Runningtime Approach -


The function uses a list of int and in the growing sequence produces unique elements in the list. For example:

  Single ([4,1,4,17,1]) => [1,4,17]  

I can only do O (N ^ 2) in the running time and it is surprising how the change in time without running. DEF singles (LST): if LST == []: Returns [] F-rest: rest_fn = list (filter (lambda x: x! = Lst [0], lst [1: ]) Return [Lst [0]] + singles (rest_fun)

discussion above According to that, the copy (which has been cited, which is linked with the list of more detailed tasks, the complexity of the sorted time should be O (nlogn). The set should have time complexity (n) Therefore, Sorted (set) < / Code> Time complexity O (n) + O (nlogn) = O (nlogn)

should be edited: If you can not use the set, then you should mention it, but a signal If you use a deck, then you can still draw a single thing in O (n) (in which o (1) worst Case insertion is).

  rez = deque () last = for the value in the sorted (input): if val! = Last: Rez.add (val) # or whatever A Final = val  
to add at the end of the list

No comments:

Post a Comment