Archived

This topic is now archived and is closed to further replies.

common numbers

This topic is 5654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I search a file to find the numbers that most commonly appear in said file? Thanks. -AJ C:\DOS C:\DOS\RUN RUN\DOS\RUN -Comic Book Store Guy''s t-shirt that I saw on the Simpsons, although it didn''t actually come from the Simpsons. http://vdsoft.netfirms.com/home.html

Share this post


Link to post
Share on other sites
How complex do you want to get, do you simply want to find the top 1/2/3 most frequent numbers in the file, or are you looking for statistical functions that will consider common ranges (for instance [1,2,3,4,5] will return 3 as the most common number). What size are the numbers (8bit, 16bit, 32bit, floating point?)

Share this post


Link to post
Share on other sites
You''re actually right on the nose, I want to be able to find the top 3 numbers found in a given file. And the numbers are just regular ints, I forgot what size those are though. Thanks.

-AJ

C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

-Comic Book Store Guy''s t-shirt that I saw on the Simpsons, although it didn''t actually come from the Simpsons.

http://vdsoft.netfirms.com/home.html

Share this post


Link to post
Share on other sites
I''m working on something similiar at the moment. Perhaps something along the lines of the Distribution counting sort will work to solve your problem.


  
Distribution Counting Sort - lends itself well to radix sort

for (j = 0; j < M; j++) count[j] = 0; // initialize the count array

for (i = 1; i <= N; i++) count[a[i]]++; // tally frequencies for each value in the target array

for (j = 1; j < M; j++) count[j] += count[j-1]; // accumulate the frequencies

for (i = N; i >= 1; i--) b[count[a[i]]--] = a[i]; // transfer values to temp array

for (i = 1; i <= N; i++) a[i] = b[i]; // transfer values back to the target array


where b is a temporary array of N elements
where M is a limit on the range of the values stored in a
that is - the values stored in a range from 0 to M - 1

in the fourth loop the accumulated freqency is used as an index into the temp array
because the accumulated value indicates the number of values less than the current value
the accumulated value is decremented, because following the transfer, there is one less
value less than the current value. The loop descends in order to keep the sort stable.

Share this post


Link to post
Share on other sites
quote:
Original post by Michalson
for instance [1,2,3,4,5] will return 3 as the most common number


No it wont....
3 is the average, and the median....
the most common number(s) is/are 1, 2, 3, 4 and 5...

Share this post


Link to post
Share on other sites