[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: help with C algorythm (find unique value in an array) could you please make changes



В Вск, 21/01/2007 в 19:13 -0500, Kamaraju Kusumanchi пишет:
> 
> 2. In the worst case, your algorithm scales as O(N^2). If I am not wrong, you 
> can do this in O(N log(N)) steps. If your N is large (say > 1000) this has a 
> huge benefit. The algorithm would be
> a. use a quicksort technique to sort the input array
There is qsort in stdlib.h (man 3 qsort) Complexity O(N * logN)
But if you need to do it yourself -- "Donald Knuth. The Art of Computer
Programming, Volume 3: Sorting and Searching" will help you
> b. compare side by side elements in the sorted array to determine for 
> uniqueness.
+ O(N)

Rather fast, at least faster, then O(N^2)



Reply to: