找到空闲数字的最佳方法 [英] best method to find the freequent numbers

查看:62
本文介绍了找到空闲数字的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个整数向量,例如[1 3 6 7 6 3 3 4 9 10]


我想找出最常出现的数字。是

快速方法。我的阵列大小很大。


我正在做的是


1.找出最大值N

2.循环1 ... N

3.计数每次发生的次数

4.输出最频繁的一次


是否有更有效的实施可用?

谢谢

I have a vector of integers, such as [1 3 6 7 6 3 3 4 9 10 ]

and I want to find out the number which occurs most frequently.what is the
quick method. My array size is huge.

what I am doing is

1. find out the maximum value N
2. loop through 1...N
3. count # times each occurred
4. output the most frequent one

Are there are more efficient implementations avaiable?
Thanks

推荐答案

Den 2006-03-14 skrev Imran< ab *************** @ de.bosch.com>:
Den 2006-03-14 skrev Imran <ab***************@de.bosch.com>:
我有一个整数向量,例如[1 3 6 7 6 3 3 4 9 10]
我想找出最常出现的数字。
快速方法是什么。我的阵列大小很大。
[snip]是否有更高效的实现可用?
谢谢
I have a vector of integers, such as [1 3 6 7 6 3 3 4 9 10 ]
and I want to find out the number which occurs most frequently.what is the
quick method. My array size is huge. [snip] Are there are more efficient implementations avaiable?
Thanks




查看:
http://www.jjj.de/fxt/demo/sort/

对于一些好的实现。


//彼得

-

我的真实电子邮件地址是:

vim -c":%s / ^ / Cr ************ @ tznvy.pbz / |:normal ggVGg?"

彩虹很漂亮。我不知道为什么要向他们开枪。



Check out:
http://www.jjj.de/fxt/demo/sort/
For some good implementations.

//Peter
--
My REAL email address is:
vim -c ":%s/^/Cr************@tznvy.pbz/|:normal ggVGg?"
"Rainbows are pretty. I don''t know why I shoot at them."


2006-03-14,Imran< ab ********** *****@de.bosch.com>写道:
On 2006-03-14, Imran <ab***************@de.bosch.com> wrote:
我有一个整数向量,如[1 3 6 7 6 3 3 4 9 10]

我想知道最多出现的数字经常。
快速方法是什么。我的阵列大小很大。

我在做什么是

1.找出最大值N
2.循环1 ... N
3.计数#次每次发生
4.输出最频繁的一次

是否有更有效的实施可用?
谢谢
I have a vector of integers, such as [1 3 6 7 6 3 3 4 9 10 ]

and I want to find out the number which occurs most frequently.what is the
quick method. My array size is huge.

what I am doing is

1. find out the maximum value N
2. loop through 1...N
3. count # times each occurred
4. output the most frequent one

Are there are more efficient implementations avaiable?
Thanks




如果整数的范围限于合理的范围。比如

65535那么你可以考虑创建一个由

整数索引的数组并递增计数。如果没有完全编写纯C

代码,它可能接近以下内容:


while(未完成)开始

nextInt = inputIntegers [readIndex ++];

countArray [nextInt] ++;

end


非常快。您可以跟踪循环中最常见的数字

或最后快速扫描。


创建count数组和循环细节掌握在你手中......



If the range of the integers is limited to something "reasonable" like
65535 then you could consider creating an array indexed by the
integer in question and incrementing the count. Without writing pure C
code completely, it might approximate to something like:

while(not finished) begin
nextInt = inputIntegers[readIndex++];
countArray[nextInt]++;
end

Very fast. You could keep track of the most common number in the loop
or do a quick scan at the end.

The creation of the count array and the loop details are in your hands...


2006年3月14日星期二08:50,Imran认为(

< dv *** *******@ns2.fe.internet.bosch.com>):
On Tuesday 14 March 2006 08:50, Imran opined (in
<dv**********@ns2.fe.internet.bosch.com>):
我有一个整数向量,例如[1 3 6 7 6 3 3 4 9 10]

我想知道最常出现的数字。什么是快速方法。我的阵列尺寸很大。

我在做什么是

1.找出最大值N


我想你意思是找到数组的大小?我希望预先知道



2.循环1 ... N
3.计数每次发生的次数
4.输出最频繁的一个

是否有更高效的实现可用?
谢谢
I have a vector of integers, such as [1 3 6 7 6 3 3 4 9 10 ]

and I want to find out the number which occurs most frequently.what is
the quick method. My array size is huge.

what I am doing is

1. find out the maximum value N
I guess you mean "find the size of the array"? I''d expect that to be
known upfront.
2. loop through 1...N
3. count # times each occurred
4. output the most frequent one

Are there are more efficient implementations avaiable?
Thanks




让我们做这个特定于C的特定:


您可以使用`qsort()`对数组进行排序。一旦排序,您只需要一个

通行证来确定最常用的数字(和它的频率),

而不需要跟踪多个计数当时

(如果包括当前最大值,则为两个)。你在上面提出的建议,

将需要为你遇到的每个唯一号码单独计算。


- -

BR,弗拉基米尔


笑的人,持续。



Let''s make this slightly C-specific:

You can use `qsort()` to sort the array. Once sorted, you need just one
pass to determine the most frequent number (and it''s frequency),
without the need to keep track of more than one count at the time
(well, two if you include current maximum). What you''ve proposed above,
would have required a separate count for every unique number you
encounter.

--
BR, Vladimir

He who laughs, lasts.


这篇关于找到空闲数字的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆