0 of 7 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 7 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、对有序数组{5,13,19,21,37,56,64,75,88,92,100} 进行二分查找,成功查找元素 19的查找长度(比较次数)是( )。 (2008真题)
2、设有 100个数据元素,采用折半搜索时,最大比较次数为( )。 (2014年普及组)
3、有一个由 4000 个整数构成的顺序表,假定表中的元素已经按升序排列,采用二分查找定位一个元素。则最多需要几次比较就能确定是否存在所查找的元素:(2009年真题)
4、对有序数组 {5,13,19,21,37,56,64,75,88,92,100} 进行二分查找,等概率的情况下查找成功的平均查找长度(平均比较次数)是( )。 (2008年真题)
5、同时查找2n个数中的最大值和最小值,最少比较次数为( ) (2014年提高组)
6、以下程序段实现了找第二小元素的算法。输入是n个不等的数,构成的数组S,输出S中第二小的数secondMin。在最坏情况下,该算法需要做( )次比较。(2014年提高组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
if(S[1]<S[2]){ FirstMin=S[1]; SecondMin=S[2]; }else{ FirstMin=S[2]; SecondMin=S[1]; } for(int i=3;i<=n;i++) if(S[i]<SecondMin){ if(S[i]<FirstMin){ SecondMin=FirstMin; FirstMin=S[i]; }else{ SecondMin=S[i]; } } |
7、 阅读程序写结果:(2013年普及组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> using namespace std; int main(){ const int SIZE = 100; int n, f, i, left, right, middle, a[SIZE]; cin>>n>>f; for (i = 1; i <= n; i++) cin>>a[i]; left = 1; right = n; do { middle = (left + right) / 2; if (f <= a[middle]) right = middle; else left = middle + 1; } while (left < right); cout<<left<<endl; return 0; } |
输入:
12 17
2 4 6 9 11 15 17 18 19 20 21 25
输出: