数据结构与算法 第一章 概论 测验

第一章 概论

1单选(2分)

下列不属于线性结构的是:
Which one of the followings does not belong to linear structure:(There is only one correct answer)

A. 队列(queue)
B. 图(graph)
C. 散列表(hash table)
D. 向量(vector)

正确答案:B

解析: A、队列:是线性表按操作分类的一种(先入先出) B、图:无序 C、散列表:目录索引型线性结构 D、向量:直接访问型线性结构

2单选(2分)

以下哪种结构是逻辑结构,而与存储和运算无关:
Which of the following structure is a logical structure regardless of the storage or algorithm:(There is only one correct answer)

A. 队列(queue)
B. 双链表(doubly linked list)
C. 数组(array)
D. 顺序表(Sequential list)

正确答案:A

解析: A、队列:可以是顺序或链式存储,是逻辑结构 B、双链表:链式存储 C、数组:按索引值从小到大存放在一片相邻的连续区域,定义了存储结构 D、顺序表:按索引值从小到大存放在一片相邻的连续区域,定义了存储结构

3多选(3分)

‌关于算法特性描述正确的有:
Which one is right about algorithm’s characterization:(there are more than one correct answers)

A. 组成算法的指令可以有限也可能无限。 Instructions which composite algorithms can be infinite or finite
B. 算法保证计算结果的正确性。Algorithm will ensure the correctness of the calculation results.
C. 算法的有穷性指算法必须在有限步骤内结束。The finite nature of algorithms means algorithm must be completed within a limited step.
D. 算法描述中下一步执行的步骤不确定。 The next step in the implementation of the algorithm described is uncertain.

正确答案:B、C
解析: A、指令必须有限 B、算法保证计算结果的正确性。 C、算法不能含有死循环,必须在有限步骤内结束 D、算法具有确定性

4多选(3分)

下列说法正确的是:
Which options may be correct?(there are more than one correct answers)

‏A. 函数f(n)是O(g(n)),当常数a足够大时,一定有函数g(n)是O(af(n))【if f(n)是O(g(n)),When constant a is big enough ,there must be g(n) is O(af(n))】
B. 如果函数f(n)是O(g(n)),g(n)是O(h(n)),那么f(n)+g(n)是O(h(n))【if f(n) is O(g(n)),g(n) is O(h(n)),so f(n)+g(n) is O(h(n))】
C. 如果函数f(n)是O(g(n)),g(n)是O(h(n)),那么f(n)是O(h(n))【 if f(n) is O(g(n)),g(n) is O(h(n)),then f(n) is O(h(n))】
D. 如果a>b>1,是,但不一定是【if a>b>1, is , may not be 】

正确答案:B、C
解析: A、(4)当f(n)=n,g(n)=n*2, 无论a多大,g(n)都不可能是O(af(n)). B、(2) 如果f(n)是O(g(n)),g(n)是O(h(n)), 则f(n)是O(h(n)),所以f(n)+g(n)是O(h(n)) C、(1) 根据O()定义可知. D、(3)logan=log(n)/log(a),logbn=log(n)/log(b),所以前者与后者只差了一个常数项,所以logbn一定是O(logan)

5多选(3分)

已知一个数组a的长度为n,求问下面这段代码的时间复杂度:
An array of a, its length is known as n. Please answer the time complexity of the following code.(There are more than one answers.)

for (i=0,length=1;i<n-1;i++){
  for (j = i+1;j<n && a[j-1]<=a[j];j++)
    if(length<j-i+1)
      length=j-i+1;
}



得分/总分

A. O ( n 2 ) O(n^2) O(n2)
B. O ( n ) O(n) O(n)
C. Θ ( n 2 ) \Theta(n^2) Θ(n2)
D. Ω ( n ) \Omega(n) Ω(n)

正确答案:A、D
解析: D、本代码实际上是求a中有序子数组中最长的长度。譬如,在[1, 8, 1, 2, 5, 0, 11, 9]中,最长的是[1, 2, 5],长度为3 。其时间复杂度与a中元素的实际取值状态相关。 1)若a的所有元素是按照降序方式排列。则外层循环n-1次,每次内层只执行一次,整个开销为θ(n) 2)若a的所有元素是按照升序方式排列。则外层循环n-1次,每次内层需要执行n-i-1次,整个开销为 θ ( n 2 ) θ(n^2) θ(n2) 所以,一般来说,时间复杂度是 Ω ( n ) Ω(n) Ω(n)的,也是 O ( n 2 ) O(n^2) O(n2)

6填空(2分)

计算运行下列程序段后m的值:
Calculate the value of m after running the following program segment

n = 9; m = 0; 
for (i=1;i<=n;i++)
  for (j = 2*i; j<=n; j++)
    m=m+1;

求m的值

正确答案:20
解析: 注意i从1到9全部遍历,j分别从2,4,6,…开始遍历到9,当i大于5时,循环不再对m进行操作.
i=1结束循环时,m=8;
i=2结束循环时,m=8+6=14;
i=3结束循环时,m=14+4=18;
i=4结束循环时,m=18+2=20;

7填空(2分)

‏由大到小写出以下时间复杂度的序列: 答案直接写标号,如:(1)(2)(3)(4)(5) (提示:系统基于字符匹配来判定答案,所以您的答案中不要出现空格)

Write the following time complexity in descending sequence:Write down the answer labels such as (1)(2)(3)(4)(5). (Hint:This problem is judged by string matching, Please make sure your answer don’t contain any blanks. )
在这里插入图片描述
正确答案:(5)(1)(2)(4)(3)
解析: 计算复杂度时,系数是可以忽略的。(5)和(1)是指数级复杂度,大于(2)(3)(4)多项式级复杂度,区别在于指数中是否有n。而(5)的指数里还有指数级复杂度的表达式,(1)的指数是n,为多项式级,故(5)比(1)复杂。对于(2)(3)(4),(2)的指数最大,为2.5,(4)的指数居中,为2,(3)的指数最小,解释如下:logn的任意实数次方的复杂度都小于n,故(logn)^4比n复杂度低,故n*(logn)^4比n*n复杂度低,故(4)比(3)复杂,故答案为(5)(1)(2)(4)(3)

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值