er,
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 3 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:sc2 (等级:2 - 初出茅庐,发帖:84) 发表:2003-07-28 11:06:52  楼主  关注此帖评分:
searching algorithm enquiry请教PROGRAMMING高手们: If i divide the interval I=[0,1) into, say, 64 subintervals, and recode the 64 left pts into an Array A[0:63] in ascending order, how can I decide which interval a random number a (- [0,1) is in with the LEAST possible loopings? The method I use now is : start from the centre A[33], check if a>A[33]. if yes, check the centre of the upper half if a>A[49]; else check centre of the lower half if a>A[17]. So on and so forth, just like the idea of a binary ADC converter. but i need 6 looping interation in order to get the answer. Any one knows faster method than this?
er,
The worst case performance is very difficult to improve, which is lg(n)

You can improve the averge case performance, by the following data structure:
(I suggested)
Divide the [0, 1) into 64 equally spanned intervels,by b1=1/64, b2=2/64, ...

Record into B which interval of A that bi belongs to.

If B[i]=B[i+1], then you meet a nice case when the randon number fall into
b[i], b[i+1], otherwise, you maybe need to divide B[i] recursively.

To implement this will be tedious. You are can compute that the average
case for this datastructure will be O(1).

Hope that will be helpful
Put your OWN COOL signature here!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:sc2 (等级:2 - 初出茅庐,发帖:84) 发表:2003-07-29 10:57:06  2楼
thanx very much for sc2's suggestion, butIf B[i]=B[i+1], it can only be deduced that the width for one of the subintervals A[j+1]-A[j]>1/64. But which subinterval the random number a resides is independent of the width of the subinterval, am i right? Actually the matrix A is a known quantity, which determines how the interval [0,1) is divided into subintervals, the widths of which might not be the same. And the random number a is the "true" variable.
welcome, and
B[i] records the A's interval ID(the index, not the real value).
and B's size is not necesarily to be 64, say, can be 200.

if B[i]=B[i+1], then B[i] is the value u want.
otherwise B[i+1]>B[i], you may just sub-divide the range [i/64, (i+1)/64).
Otherwise, you can just do a liear scan from A[B[i]] to A[B[i+1]],
the expect number of intervals tp be scanned
should be very small (O(1)). The worst case can be large as larger as
A's size (you can do a binary search again (O(lgn)),
but the overhead will be large).

Yup, A is random and sorted in increasing order?!, if u want to find
the right interval by comparison, the worst case bound is O(lgn), and
hard to improve. :)
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:sc2 (等级:2 - 初出茅庐,发帖:84) 发表:2003-07-30 11:39:09  3楼
不好意思的说,可能是我太笨了我知道B[i]是INDEX 可B[i]=B[i+1]只说明b[i],b[i+1]在相同的区间内, 能说明 a 也在这个区间内吗? a 和 b[i],b[i+1] 没任何关系吧.
we discuss it with email bah
otherwise it will be lenghy here...
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 3 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码