这是一个开放性的问题,视答题人的程度,可以往下追。 既然连binary search都没有提及,也就不再追问下面的。
最基本的回答是从头至尾逐个比较,发现相等的,即返回其位置。
达到这一步,我们再问,有可能改进效率吗?可能回答,是加一个不等比较
if (array[i] == n)
return i;
else if (array[i] > n)
return -1;
这个不等比较是否能减少平均计算量而改进效率?
这是一个开放性的问题,视答题人的程度,可以往下追。 既然连binary search都没有提及,也就不再追问下面的。
最基本的回答是从头至尾逐个比较,发现相等的,即返回其位置。
达到这一步,我们再问,有可能改进效率吗?可能回答,是加一个不等比较
if (array[i] == n)
return i;
else if (array[i] > n)
return -1;
这个不等比较是否能减少平均计算量而改进效率?
•
回复:no, that was not what we wanted to test.
-布衣之才-
♂
(162 bytes)
()
12/06/2012 postreply
21:23:22
WENXUECITY.COM does not represent or guarantee the truthfulness, accuracy, or reliability of any of communications posted by other users.
Copyright ©1998-2025 wenxuecity.com All rights reserved. Privacy Statement & Terms of Use & User Privacy Protection Policy