O(n)具有O(1 / epsilon)空间的重击者?(O(n) Heavy-Hitters with O(1/epsilon) space?)
我知道重击手的以下算法:
Algorithm findHeavyHitters(epsilon, inputStream) integer k = ceiling(1 / epsilon) - 1 initialize hashmap H of size k while an item i from the input stream arrives: if H[i] exists increment the value associated with H[i] elsif number of items in H < k put H[i] into map with value of 1 elseif there exists an entry j with a value of 0 remove j and put H[i] into map with value of 1 else decrement all values in H by 1 endwhile return H
如果我错了,请纠正我,但这个算法不能在O(n)中运行。 是否可以修改此算法,使其在O(n)中运行,同时保持O(1 / epsilon)空间的使用?
对于数据流,算法的要点是返回顶部epsilon * t项。 Epsilon以百分比形式给出(例如,输入0.1表示至少发生10%的数据)。
I know of the following algorithm for heavy-hitters:
Algorithm findHeavyHitters(epsilon, inputStream) integer k = ceiling(1 / epsilon) - 1 initialize hashmap H of size k while an item i from the input stream arrives: if H[i] exists increment the value associated with H[i] elsif number of items in H < k put H[i] into map with value of 1 elseif there exists an entry j with a value of 0 remove j and put H[i] into map with value of 1 else decrement all values in H by 1 endwhile return H
Correct me if I'm wrong, but this algorithm does not run in O(n). Is it possible to modify this algorithm so that it runs in O(n) while maintaining the O(1/epsilon) use of space?
For a stream of data, the point of the algorithm is to return the top epsilon*t items. Epsilon is given as a percentage (e.g. input 0.1 for data that occurs at least 10% of the time).
原文:https://stackoverflow.com/questions/37851407
最满意答案
至少为了解决这个问题,你的类需要重写Object.Equals()。 另外实现IEquatable是个好主意。
Your class needs to override Object.Equals() at least for that comparison to work out. Also implementing IEquatable is a good idea.
More information: Guidelines for Overloading Equals() and Operator == (C# Programming Guide)
相关问答
更多-
如何检查两个变量是否在Python中引用同一个对象?(How do I check if two variables reference the same object in Python?)[2023-01-17]
您可以使用is来检查两个对象是否具有相同的身份。 >>> x = [1, 2, 3] >>> y = [1, 2, 3] >>> x == y True >>> x is y False You can use is to check if two objects have the same identity. >>> x = [1, 2, 3] >>> y = [1, 2, 3] >>> x == y True >>> x is y False -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
这样做怎么样: - where datediff(minute,DATEADD(MINUTE, @Duration, @NotificationTime),GETDATE()) = 0 How about doing like this:- where datediff(minute,DATEADD(MINUTE, @Duration, @NotificationTime),GETDATE()) = 0
-
由于您的值是数字,因此可以通过在对象上使用标志属性来实现。 首先让我们用你拥有的离散变量来做,然后回过头来看看用wrong数组来做: 使用离散变量:( 编辑:我真的不喜欢这种方法,强烈建议跳过下一个) var correct, wrong1, wrong2, wrong3, wrong4, flags, foundDuplicate, dbcount; dbcount = 20; //set correct, dbcount is at 20ish now, will end up in the ...
-
等变量 - 批量(Equal variables - Batch)[2024-01-20]
保存下一个代码片段,可能名为blabla.bat : @Echo OFF setlocal set complete_name=%1 if "%complete_name:9000=%"=="%complete_name%" ( if "%complete_name:930=%"=="%complete_name%" ( if "%complete_name:310=%"=="%complete_name%" ( echo problem ) else ( ... -
至少为了解决这个问题,你的类需要重写Object.Equals()。 另外实现IEquatable是个好主意。 更多信息: 重载Equals()和运算符==(C#编程指南)的指导原则 Your class needs to override Object.Equals() at least for that comparison to work out. Also implementing IEquatable is a good idea. More information: Guidelines for ...
-
if "%var1%" neq "%var2%" 要么 if not "%var1%"=="%var2%" help if在控制台窗口中输入help if以获取更多信息。 如果其中一个变量包含空格,您还应习惯将==符号的两边用引号括起来。 if "%var1%" neq "%var2%" or if not "%var1%"=="%var2%" Type help if in a console window for more info. You should also get into the h ...
-
仅在运行时才知道类型时,如果不使用反射,则不能在通用中使用它。 但是,您的任务比这更简单 - 您可以使用类型相等来实现所需的结果: Type targetType = pObject.GetType(); if (SomeList.Any(o => targetType.Equals(o.GetType()))) { ... } When the type is known only at runtime, you cannot use it in a generic without using ...
-
如何检查变量是否等于多个其他变量?(How do I check for a variable to be equal to multiple other variables?)[2023-12-31]
这是FOR循环的解决方案,可扩展到几乎任何数量的可接受用户的回复: rem remove variable _match set "_match=" set /p FILEINPUT="1, 2 or 3?" rem check whether user's reply is in (1 2) set for %%G in (1 2) do if "%FILEINPUT%"=="%%~G" set "_match=%%~G" if defined _match ( echo ... -
如何检查shell脚本中的两个变量是否指向同一个文件夹?(How to check if two variables in a shell script point to the same folder?)[2022-06-12]
var1="/home/ps/temp/.." var2="/home/ps/" if [ "$(readlink -f "$var1")" == "$(readlink -f "$var2")" ];then echo "they are pointing to same directory...." else echo "NOOOOO they are different" fi 来自man readlink : -f, - canonicalize 通过递归地跟随给定名称的 ...