[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



On Sunday 21 January 2007 18:18, Jabka atu wrote:
> Good evening to all,...
> i wrote a small algorythm (in C ) to find how many uniqe value are in an
> array ..
> then change the size of the array to store all the unique values ..

Couple of comments:

1. Your code is working fine for me. Though the way in which output is 
presented could be enhanced by using a new line character.

change
  printf("The size of the array %d",n);
to
  printf("The size of the array %d\n",n);

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
b. compare side by side elements in the sorted array to determine for 
uniqueness.

The quicksort and similar algorithms can be found in numerical recipes book.

hth
raju


-- 
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/

----------------------------------------------------------------------
Click for free info on human resource careers and make $150K/ year
http://tags.bluebottle.com/fc/CAaCMPJdTDvUk3LCiWcdMdg9gIjyQWQN/



Reply to: