数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版


第一章 概论 第一章 概论 测验

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

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

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)
答案: 队列(queue)

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

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

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

A:如果函数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))
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:如果a>b>1,数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第1张数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第2张,但数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第3张不一定是数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第4张if a>b>1,数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第1张 is 数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第2张, 数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第3张 may not be 数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第4张
D:函数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))
答案: 如果函数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));
如果函数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))

5、 已知一个数组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:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第9张
B:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第10张
C:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第11张
D:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第12张
答案: 数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第9张;
数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第10张

6、 计算运行下列程序段后m的值:Calculate the value of m after running the following program segmentn = 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、 由大到小写出以下时间复杂度的序列: 答案直接写标号,如:(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. )数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第15张
答案: (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比nn复杂度低,故(4)比(3)复杂,故答案为(5)(1)(2)(4)(3)

第二章 线性表 第二章 线性表测验

1、 下面关于线性表的叙述中,正确的是哪些?Which of the followings about linear list are correct?(There are more than one answers.)Select the answer that matches

A:线性表采用顺序存储,必须占用一片连续的存储单元。Linear lists use sequential storage which must occupy a continuous memory units.
B:线性表采用顺序存储,便于进行插入和删除操作。Linear lists using sequential storage, it is easy to do insert and delete operations.
C:线性表采用链接存储,不必占用一片连续的存储单元。Linear lists using the linked storage, do not occupy a continuous memory units.
D:线性表采用链接存储,便于插入和删除操作。Linear lists using the linked storage, it is easy for insert and deleting operations.
答案: 线性表采用顺序存储,必须占用一片连续的存储单元。Linear lists use sequential storage which must occupy a continuous memory units.;
线性表采用链接存储,不必占用一片连续的存储单元。Linear lists using the linked storage, do not occupy a continuous memory units.;
线性表采用链接存储,便于插入和删除操作。Linear lists using the linked storage, it is easy for insert and deleting operations.

2、 下面的叙述中正确的是:Select the answer that matches (There are more than one correct answers)

A:线性表在链式存储时,查找第i个元素的时间与i的数值无关。When the linear list stored in linked form, the time to find the i-th element is regardless of the value of i.
B:线性表在顺序存储时,查找第i个元素的时间与i的数值成正比。When the linear list stored sequentially, the time to find the i-th element is proportional to value with i.
C:线性表在顺序存储时,查找第i个元素的时间与i的数值无关。When the linear list stored sequentially, the time to find the i-th element is regardless of the value of i.
D:线性表在链式存储时,插入第i个元素的时间与i的数值成正比。When linear lists stored in the linked form, the time to insert the i-th element is proportional to value with i.
答案: 线性表在顺序存储时,查找第i个元素的时间与i的数值无关。When the linear list stored sequentially, the time to find the i-th element is regardless of the value of i.;
线性表在链式存储时,插入第i个元素的时间与i的数值成正比。When linear lists stored in the linked form, the time to insert the i-th element is proportional to value with i.

3、 完成在双循环链表结点p之后插入s的操作为:The operation to insert s after the doubly circular linked list’s node p is: (There are more than one answers.)

A:p->next->prev=s; s->prev=p; s->next=p->next; p->next=s; 
B:p->next->prev=s; p->next=s; s->prev=p; s->next=p->next;
C:s->prev=p; s->next=p->next; p->next=s; p->next->prev=s;
D:s->next=p->next; p->next->prev=s; s->prev=p; p->next=s;
答案: p->next->prev=s; s->prev=p; s->next=p->next; p->next=s; ;
s->next=p->next; p->next->prev=s; s->prev=p; p->next=s;

4、 对于一个具有n个结点的单链表,在已知的结点p后插入一个新结点的时间复杂度为O(),在给定值为x的结点后插入一个新结点的时间复杂度为O()。(请依次填入,格式为(a)(b),如果您的答案中出现字母,请使用小写;后一空系统基于字符匹配来判定答案,所以您的答案中不要出现空格)For a single linked list with n nodes, and after a known node p to insert a new node, the time complexity is O (); after a given node with x value insert a new node, the time complexity is O (). (If your answer contains letters, use lowercase one.The second blank is judged by string matching, Please make sure your answer don’t contain any blanks. )
答案: (1)(n)
分析:已知结点后插入,不需要移动其他结点位置,所以为O(1) 2. 先要查找到值为x的结点,需要O(n),再插入,不需要移动其他结点位置,需要O(1),总共需要O(n)+O(1)=O(n)

5、 设某循环链表长度为n,并设其中一节点为p1,然后按照链表的顺序将后面的节点依次命名为p2,p3,…,pn,那么请问pn.next=____(答案为一个节点名,注意所有字母为小写且答案中不包含空格)
答案: p1
分析:循环链表尾结点的next会指向头结点

第三章 栈与队列 第三章 栈与队列测验

1、 设栈S 和队列Q 的初始状态为空,元素e1,e2,e3,e4,e5和e6依次通过栈S,一个元素出栈后即进队列Q,若6 个元素出队的序列是e2,e4,e3,e6,e5,e1则栈S的容量至少应该是___。Assume that the stack S and queue Q’s initial state is empty, the elements e1, e2, e3, e4, e5 and e6 followed through stack S, an element out the stack means into the queue Q. If the sequence the six elements out of the queue is e2, e4, e3, e6, e5, e1 then stack S of capacity should be at least _____. (There is only one correct answer)

A:2
B:3
C:4
D:6
答案: 3

2、 现有中缀表达式E=((100-4)/3+3(36-7))2。以下哪个是与E等价的后缀表达式?Existing infix expression E = ((100-4) / 3 + 3 * (36-7)) * 2. Which of the following is the equivalent postfix expression of E? (There is only one correct answer)

A:( ( 100 4 – ) 3 / 3 ( 36 7 – ) * + ) 2
B:
 + / – 100 4 3 * 3 – 36 7 2
C:100 4 – 3 / 3 36 7 – * + 2
D:
 ( + / ( – 100 4 ) 3 * 3 ( – 36 7 ) ) 2
答案: 100 4 – 3 / 3 36 7 – * + 2 *

3、 队列的特点包括:Queue’ features include:(There are more than one answers.)

A:后进先出Last-in first-out (LIFO)
B:先进后出First-in last-out (FILO)
C:先进先出First-in first-out (FIFO)
D:后进后出 Last-in last-out (LILO)
答案: 先进先出First-in first-out (FIFO);
后进后出 Last-in last-out (LILO)

4、 以下循环队列的实现方式中,长度为n的队列,所能容纳的元素个数也为n的有:In the following realizing ways of circular queue, the queue whose length is n can also contain the number of n elements is:(There are more than one answers.)

A:只用front和rear两个指针标记队列的头和尾,两个指针均为实指Only use front and rear as the queue’s head and tail pointers and the two pointers are actually referring to.
B:用front和rear两个指针标记队列的头和尾,并用整型变量len记录队列元素数With the queue’s head and tail pointers marked as front and rear, use the integer variable len to record the number of elements.
C:用front和rear两个指针标记队列的头和尾,并用布尔型变量empty记录队列是否为空With the queue’s head and tail pointers marked as front and rear, use Boolean variable empty record whether the queue is empty.
D:只用front和rear两个指针标记队列的头和尾,两个指针均为虚指Only use front and rear as the queue’s head and tail pointers and the two pointers are virtually referring to.
答案: 用front和rear两个指针标记队列的头和尾,并用整型变量len记录队列元素数With the queue’s head and tail pointers marked as front and rear, use the integer variable len to record the number of elements.;
用front和rear两个指针标记队列的头和尾,并用布尔型变量empty记录队列是否为空With the queue’s head and tail pointers marked as front and rear, use Boolean variable empty record whether the queue is empty.

5、 编号为1,2,3,4的四辆列车,顺序开进一个栈式结构的站台;则开出车站的顺序有__种可能。 注释:例如 1, 2, 3, 4 或 4, 3, 2,1 就是其中两种可能出站序列;而 4, 3, 1, 2 是 非法序列。Numbered 1,2,3,4 four trains, orderly entered a stack structure station. How many possible leaving sequences of that four trains ? ____ . Note: For instance, the leaving sequence could be 1,2,3,4 or 4,3,2,1 these two possibilities, but 4, 3, 1, 2 is not a possible sequence.
答案: 14
分析:出栈次序是经典的问题,与组合数学中的卡特兰数密切相关,以下只介绍朴素的思路。
先进站的车可以先开,也可以后开。只有一种情况不可能:编号大的车开出后,比其编号小的车反序开出。也即编号大的车开出后,编号比其小的车只能由大到小依次开出(中间可以插入编号更大的车,但此车后面的编号小的车也要遵守此规则)。例如312的开出顺序是不可能的。对所有车进行全排列共有24种出法。但4开头的只能有一种:4321。所以少了3的全排列-1=5种。三开头的时候,必须先2后1开出,先1后2时4的位置有三种:3124、3142、3412,所以少了三种。1或2开头的时候,后面的车如果是4,则最后两辆必须是3、2或3、1。所以又少了1423、2413两种。总共少了5+3+2=10种,有24-10=14种开出法。
下面用+表示进站,-表示出站:
1234:1+ ;1- ;2+ ;2- ;3+ ;3- ;4+ ;4-
1243:1+ ;1- ;2+ ;2- ;3+ ;4+ ;4- ;3-
1324:1+ ;1- ;2+ ;3+ ;3- ;2- ;4+ ;4-
1342:1+ ;1- ;2+ ;3+ ;3- ;4+ ;4- ;2-
1432:1+ ;1- ;2+ ;3+ ;4+ ;4- ;3- ;2-
2134:1+ ;2+ ;2- ;1- ;3+ ;3- ;4+ ;4-
2143:1+ ;2+ ;2- ;1- ;3+ ;4+ ;4- ;3-
2314:1+ ;2+ ;2- ;3+ ;3- ;1- ;4+ ;4-
2341:1+ ;2+ ;2- ;3+ ;3- ;4+ ;4- ;1-
2431:1+ ;2+ ;2- ;3+ ;4+ ;4- ;3- ;1-
3214:1+ ;2+ ;3+ ;3- ;2- ;1- ;4+ ;4-
3241:1+ ;2+ ;3+ ;3- ;2- ;4+ ;4- ;1-
3421:1+ ;2+ ;3+ ;3- ;4+ ;4- ;2- ;1-
4321:1+ ;2+ ;3+ ;4+ ;4- ;3- ;2- ;1-;

6、 双端队列可以在队列的两端进行插入和删除操作,既可在队尾进行插入/删除,又可在队头进行插入/删除。现有4个不同的元素顺序输入到双端队列,那么可以得到_种不同的排列。double-ended queue can insert and delete operations on both ends of the queue. That it can insert / delete at its tail, but also at the head. Existing 4 different elements sequentially input to the double-ended queue, you can get ___ different permutations.
答案: 8
分析:第一个元素从左或右入队没有区别,以后每个元素都有从左和从右两种入队方式,即有2^{x-1}种方法。

第五章 二叉树 第五章 二叉树前半部分(5.1~5.4)测验

1、 下列关于二叉树性质的说法正确的有:(多选)Which sentences of the followings are right about a binary tree’s characterization:(There are more than one correct answers)

A:非空满二叉树的结点个数一定为奇数个。 The amount of nodes of a full binary tree with at least one node must be odd.
B:非完全二叉树也可以用像完全二叉树那样使用顺序存储结构进行存储。Sequential storing structure can also be used to store an incomplete binary tree just like to store a complete binary tree.
C:当一棵完全二叉树是满二叉树时,叶子结点不一定集中在最下面一层。If a complete binary tree is a full binary tree, it will be possible that leaf nodes is no t on the nethermost layer.
D:完全二叉树最多只有最下面的一层结点度数可以小于2。For a complete binary tree, only the degrees of nodes on the nethermost layer could be less than 2.
E:一棵非空二叉树的为空的外部结点数目等于其结点数加1。The amount of external null nodes in a binary tree with at least one node equals to its amount of nodes plus 1.
F:满二叉树的所有结点的度均为2。All degrees of nodes in a full binary tree are 2.
答案: 非空满二叉树的结点个数一定为奇数个。 The amount of nodes of a full binary tree with at least one node must be odd.;
当一棵完全二叉树是满二叉树时,叶子结点不一定集中在最下面一层。If a complete binary tree is a full binary tree, it will be possible that leaf nodes is no t on the nethermost layer.;
一棵非空二叉树的为空的外部结点数目等于其结点数加1。The amount of external null nodes in a binary tree with at least one node equals to its amount of nodes plus 1.

2、 下列关于二叉树遍历的说法正确的有:Which sentences of the followings are right about traversal of a binary tree:

A:前序和中序遍历的顺序恰好一样的二叉树,只能是空二叉树或者独根二叉树这两种情况。Only the sequences of preorder and infix order of the binary tree with no nodes or only one node are the same.
B:所有结点左子树为空的二叉树的前序和中序遍历顺序恰好一样。The sequences of preorder and infix order of a binary tree with all nodes without left child tree are the same.
C:所有结点右子树为空的二叉树的前序和中序遍历顺序恰好一样。The sequences of preorder and infix order of a binary tree with all nodes without right child tree are the same.
D:只有空二叉树和一个根结点的二叉树这两种二叉树的前序和后序遍历的顺序恰好一样。Only the sequences of preorder and post order of the binary tree with no nodes or only one node are the same.
E:所有结点左子树为空的二叉树的前序和后序遍历顺序恰好一样。The sequences of preorder and post order of a binary tree with all nodes without left child tree are the same.
F:所有结点右子树为空的二叉树的前序和后序遍历顺序恰好一样。The sequences of preorder and post order of a binary tree with all nodes without left child tree are the same.
G:只有空二叉树和一个根结点的二叉树这两种二叉树的中序和后序遍历的顺序恰好一样。Only the sequences of infix order and post order of the binary tree with no nodes or only one node are the same.
H:所有结点左子树为空的二叉树的中序和后序遍历顺序恰好一样。The sequences of infix order and post order of a binary tree with all nodes without left child tree are the same.
I:所有结点右子树为空的二叉树的中序和后序遍历顺序恰好一样。The sequences of infix order and post order of a binary tree with all nodes without right child tree are the same.
J: 存在一棵非空二叉树,它的前序、中序和后序遍历都是一样的。There exists a binary tree with at least one node, whose preorder, infix order and post order are all the same.
答案: 所有结点左子树为空的二叉树的前序和中序遍历顺序恰好一样。The sequences of preorder and infix order of a binary tree with all nodes without left child tree are the same.;
只有空二叉树和一个根结点的二叉树这两种二叉树的前序和后序遍历的顺序恰好一样。Only the sequences of preorder and post order of the binary tree with no nodes or only one node are the same.;
所有结点右子树为空的二叉树的中序和后序遍历顺序恰好一样。The sequences of infix order and post order of a binary tree with all nodes without right child tree are the same.;

 存在一棵非空二叉树,它的前序、中序和后序遍历都是一样的。There exists a binary tree with at least one node, whose preorder, infix order and post order are all the same.

3、 一棵有510个结点的完全二叉树的高度为多少?(独根树高度为1)What is the height of a complete binary tree with 510 nodes? (the height of a tree with only a root is 1)
答案: 9

4、 一棵有512个结点的完全二叉树的高度为多少?(独根树高度为1)What is the height of a complete binary tree with 512 nodes? (the height of a tree with only a root is 1)
答案: 10

5、 在一棵非空二叉树中,若度为0的结点的个数n,度为2的结点个数为m,则有n=_ (系统根据字符串匹配来判定答案,所以您的答案中请不要包含空格) For a binary tree with at least one node, if there are n nodes with degree 0 and m nodes with degree 2, then n = _(This problem is judged by string matching, Please make sure your answer don’t contain any blanks.)
答案: m+1

6、 已知一棵树的前序遍历为ABDEGCF,中序遍历为DBGEACF,求这棵树的后序遍历。(字母和字母之间不要有空格)The preorder sequence of a tree is ABDEGCF, and its infix order sequence is DBGEACF, please write down its post order sequence. (There is no blank space between letters)
答案: DGEBFCA

7、 已知一棵树的中序遍历为DBGEACF,后序遍历为DGEBFCA,求这棵树的前序遍历。(字母和字母之间不要有空格)The infix order sequence of a tree is DBGEACF, and its post order sequence is DGEBFCA, please write down its preorder sequence. (There is no blank space between letters)
答案: ABDEGCF

8、 请写出下面这棵二叉树的前序遍历(字母和字母之间不要有空格)
Please write down the preorder sequence of the following binary tree. (There is no blank space between letters)数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第16张
答案: BEXLMKCPDHQA

9、 请写出下面这棵二叉树的中序遍历(字母和字母之间不要有空格)
Please write down the infix order sequence of the following binary tree. (There is no blank space between letters)数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第17张
答案: LXMECKPBQHDA

10、 请写出下面这棵二叉树的后序遍历(字母和字母之间不要有空格)
Please write down the post order sequence of the following binary tree. (There is no blank space between letters)数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第18张
答案: LMXCPKEQHADB

第五章 二叉树 第五章 二叉树后半部分(5.5~5.7)测验

1、 下列关于二叉搜索树的说法正确的有Which sentences of the followings are right about binary search tree:

A:二叉搜索树按照中序遍历将各结点打印出将各结点打印出来,将得到按照由小到大的排列。If we print a binary search tree’s nodes according its infix order, the sequence will be from small to large.
B:如果结点χ的左子树有右子树,则存在某个结点的值介于结点χ的值和χ左儿子的值之间,并且这个结点在$$x$$的左子树之中。If the left child tree of a node x has a right child tree, then there exists some node whose value is between the value of node x and the value of its left child node, and this node is on the left child tree of node x.
C:当根结点没有左儿子时,根结点一定是值最小的结点。If the root node doesn’t have left child, it must be the node with the smallest value.
D: 二叉搜索树一定是满二叉树。A binary search tree must be a full binary tree.
E:二叉搜索树一定是完全二叉树。A binary search tree must be a complete binary tree.
F: 从根结点一直沿右儿子向下找不一定能找到树中值最大的结点。Along the right child of nodes all the time from the root node, it is possible that we couldn’t find out the node with the largest value.
答案: 二叉搜索树按照中序遍历将各结点打印出将各结点打印出来,将得到按照由小到大的排列。If we print a binary search tree’s nodes according its infix order, the sequence will be from small to large.;
如果结点χ的左子树有右子树,则存在某个结点的值介于结点χ的值和χ左儿子的值之间,并且这个结点在$$x$$的左子树之中。If the left child tree of a node x has a right child tree, then there exists some node whose value is between the value of node x and the value of its left child node, and this node is on the left child tree of node x.;
当根结点没有左儿子时,根结点一定是值最小的结点。If the root node doesn’t have left child, it must be the node with the smallest value.

2、 下列关于堆的说法正确的有: Which sentences of the followings are right:

A:堆一定是满二叉树。A heap must be a full binary tree.
B:最小堆中,最下面一层最靠右的结点一定是权值最大的结点。In a minimum heap, the rightest node on the nethermost layer must be the node with the largest value.
C:堆是实现优先队列的惟一方法。A heap is the only method to implement a priority queue.
D:堆一定是完全二叉树。A heap must be a complete binary tree.
E:最小堆中,某个结点左子树中最大的结点可能比右子树中最小的结点小。In a minimum heap, the largest value on some node’s left child tree could be possibly smaller than the smallest value of its right child tree.
F:使用筛选法建堆要比将元素一个一个插入堆来建堆效率高。Screening method has a higher efficiency than inserting elements one by one while constructing a heap.
答案: 堆一定是完全二叉树。A heap must be a complete binary tree.;
最小堆中,某个结点左子树中最大的结点可能比右子树中最小的结点小。In a minimum heap, the largest value on some node’s left child tree could be possibly smaller than the smallest value of its right child tree.;
使用筛选法建堆要比将元素一个一个插入堆来建堆效率高。Screening method has a higher efficiency than inserting elements one by one while constructing a heap.

3、 下列关于Huffman树和Huffman编码的说法正确的有:Which sentences of the followings are right about Huffman tree and Huffman code:

A:Huffman树一定是满二叉树。A Huffman tree must be a full binary tree.
B:Huffman编码是一种前缀编码。Huffman code is a kind of prefix code.
C:Huffman树一定是完全二叉树。A Huffman tree must be a complete binary tree.
D:Huffman编码中所有编码都是等长的。All codes in a Huffman code have the same length.
E: 对于同样的一组权值两两不同的内容可以得到不同的Huffman编码方案。Different content with the same group of weights can get different Huffman codes.
F:使用频率越高的字母,Huffman编码越长。The higher a letter’s frequency is, the longer its Huffman code is. 
答案: Huffman树一定是满二叉树。A Huffman tree must be a full binary tree.;
Huffman编码是一种前缀编码。Huffman code is a kind of prefix code.;
 对于同样的一组权值两两不同的内容可以得到不同的Huffman编码方案。Different content with the same group of weights can get different Huffman codes.

4、 一组包含不同权的字母已经对应好Huffman编码,如果某一个字母对应编码001,下面说法正确的有A group of letters with different weights has corresponded with Huffman codes, if a letter’s corresponding code is 001, which sentences of the followings are right:

A: 以001开头的编码不可能对应其他字母。A code beginning with 001 couldn’t correspond with other letters.
B:以000开头的编码不可能对应任何字母。Codes beginning with 000 couldn’t correspond with any letter.
C: 以01开头和1开头的编码肯定对应某个字母。Codes beginning with 01 or 1 must correspongding with some letters.
D:建好的Huffman树至少包含4个叶结点。The Huffman tree contains at least 4 leaf nodes.
E:编码0和00可能对应于其他字母。Code 0 and 00 could corresponding with other letters.
答案:  以001开头的编码不可能对应其他字母。A code beginning with 001 couldn’t correspond with other letters.;
 以01开头和1开头的编码肯定对应某个字母。Codes beginning with 01 or 1 must correspongding with some letters.;
建好的Huffman树至少包含4个叶结点。The Huffman tree contains at least 4 leaf nodes.

5、 如果按关键码值递增的顺序依次将n个关键码值插入到二叉搜索树中,如果对这样的二叉搜索树进行检索时,每次检索的字符都等概率的从这n个关键码值中选取,平均比较次数为多少?If we insert n key values to a binary search tree successively from small to large, when we search this binary search tree, each time the search character is selected from these n key values with the same possibility, then how many times will the comparison be on average?
答案: (以下答案任选其一都对)(n+1)/2;
(1+n)/2

6、 从空二叉树开始,严格按照二叉搜索树的插入算法(不进行旋转平衡),逐个插入关键码{18,73,10,5,68,99,27,41,51,32,25}构造出一棵二叉搜索树,对该二叉搜索树按照前序遍历得到的序列为?(答案中每两个元素之间用一个空格隔开)From a null binary tree, insert key values {18, 73, 10, 5, 68, 99, 27, 41, 51, 32, 25} successively according to the insertion algorithm of a binary search tree strictly (no rotation and balance) to construct a binary search tree. Please write down the sequence of preorder of this binary search tree. (There is one blank space between two elements)
答案: 18 10 5 73 68 27 25 41 32 51 99

7、 从空二叉树开始,严格按照二叉搜索树的插入算法(不进行旋转平衡),逐个插入关键码{18,73,10,5,68,99,27,41,51,32,25}构造出一棵二叉搜索树,对该二叉搜索树按照后序遍历得到的序列为?(答案中每两个元素之间用一个空格隔开)From a null binary tree, insert key values {18, 73, 10, 5, 68, 99, 27, 41, 51, 32, 25} successively according to the insertion algorithm of a binary search tree strictly (no rotation and balance) to construct a binary search tree. Please write down the sequence of post order of this binary search tree. (There is one blank space between two elements)
答案: 5 10 25 32 51 41 27 68 99 73 18

8、 从空二叉树开始,严格按照二叉搜索树的插入算法(不进行旋转平衡),逐个插入关键码构造出一棵二叉树,以怎样的顺序插入关键码集合{14,32,47,6,9,12,78,63,29,81}可以使得树的深度最小?请依次写出插入到树中的元素,每两个元素之间用一个空格隔开。如果有多组满足要求的方案,请使得你的答案中先插入的元素尽可能的小。From a null binary tree, insert key values successively according to the insertion algorithm of a binary search tree strictly (no rotation and balance) to construct a binary search tree. What is the insertion sequence that could make the tree have a smallest depth with a key value set {14,32,47,6,9,12,78,63,29,81}? Please write down the elements successively, and there is one blank space between two elements. If there are more than one answer that meet the condition, please make the element which needs to be inserted first as small as possible in your answer.
答案: 12 6 9 47 29 14 32 78 63 81

9、 对于关键码序列{38,64,52,15,73,40,48,55,26,12},用筛选法建最小值堆,若一旦发现逆序对就进行交换,共需要交换元素多少次?For the key value sequence {38,64,52,15,73,40,48,55,26,12}, use the screening method to constuct a minimum heap, if we exchange them when we find reversed order, then how many times should we exchange them?
答案: 6

10、 对于如下图所示的最大堆,删除掉最大的元素后,堆的前序遍历结果是For the following maximum heap, after deleting the maximum element, the preorder traversal sequence is请依次写出插入到树中的元素,每两个元素之间用一个空格隔开。Please write down the elements successively, and there is one blank space between two elements.数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第19张
答案: 59 43 24 12 23 37 28 5 57 48 3

11、 对于如下图所示的最大堆,删除掉最大的元素后,堆的后序遍历结果是For the following maximum heap, after deleting the maximum element, the post order traversal sequence is数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第20张
答案: 12 23 24 28 5 37 43 48 3 57 59

12、 下表展示了在一段文本中每个字母出现的次数。The frequencies that each letter appears in a paragraph is represented as follow.数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第21张对于这段文本使用Huffman编码相较使用等长编码能够节约多少比特的空间?Comparing to use codes that have the same length, how many bits of space could be saved when we use Huffman code for the paragraph?数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第22张
答案: 36

13、 对于给定的一组权W={1,4,9,16,25,36,49,64,81,100},构造一棵具有最小带权外部路径长度的三叉树,写出这棵树的带权外部路径长度。For a given group of weights W={1, 4, 9, 16, 25, 36, 49, 64, 81, 100}, please construct a ternary tree with a minimum weighted route length and write down this weighted route length.
答案: 705

14、 请阅读下面一段代码 Please read the following codeC++:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第23张Python:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第24张若此段代码的作用是用来进行前序遍历,那么应该在几号访问点进行访问?(只需要填写数字)if this code is used to do a preorder traversal, which visiting point should be visited? (You only need to write down the number)
答案: 1

15、 请阅读下面一段代码Please read the following codeC++:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第25张Python:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第26张若此段代码的作用是用来进行中序遍历,那么应该在几号访问点进行访问?(只需要填写数字)if this code is used to do an infix order traversal, which visiting point should be visited? (You only need to write down the number)
答案: 2

16、 请阅读下面一段代码Please read the following code C++:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第27张Python:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第28张若此段代码的作用是用来进行后序遍历,那么应该在几号访问点进行访问?(只需要填写数字)if this code is used to do an post order traversal, which visiting point should be visited? (You only need to write down the number)
答案: 3

第四章 字符串 第四章 字符串测验

1、 设有两个串p和q,其中q是p的子串,求q在p中首次出现的位置的算法称为( )(单选)There are two strings p q, q is p’s substring. The algorithm to search the first time q appeared in p is called ( )(There is only one correct answer)

A:求子串 Seeking substring
B:联接 Concatenation
C:匹配  Matching
D:求串长  Seeking length
答案: 匹配  Matching

2、 下列说法正确的是:(单选) Which of the following statements is correct? (There is only one correct answer)

A:空串就是空白串“Empty string” is blank string.
B:空串是任意字符串的子串 Empty string is a substring of arbitrary string.
C:串只可以采用顺序存储,不可以采用链式存储 String only can be stored in sequential method and cannot be stored in linked method.
D:在C++标准中,char S[M]最多能表示长度为M的字符串 In C ++ standards, char S[M] can represent up to a string of length M.
答案: 空串是任意字符串的子串 Empty string is a substring of arbitrary string.

3、 若串S1=‘ABCDEFG’, S2=‘9898’ ,S3=‘###’,S4=‘012345’,执行       concat(replace(S1,substr(S1,length(S2),length(S3)),S3),substr(S4,index(S2,‘8’),length(S2)))注意:substr(S,i,j)是对字符串S的下标为i开始取j个字符,这里的下标是从0开始的(单选)If the string S1 = ‘ABCDEFG’, S2 = ‘9898’, S3 = ‘###’, S4 = ‘012345’, execute concat (replace (S1, substr (S1, length (S2), length (S3)), S3), substr (S4, index (S2, ‘8’), length (S2)))  Note substr (S, i, j) is the operation to take string S’s j characters from subscript i. Subscript here is starting from 0.(There is only one correct answer)

A:ABC###G0123
B:ABCD###2345
C:ABCD###1234
D:ABC###G2345
答案: ABCD###1234

4、 下面关于串的的叙述中,哪一个是不正确的:(单选) Which of the following descriptions about string is not correct? (There is only one correct answer)

A:串是字符的有限序列 String is a finite sequence of characters.
B:模式匹配是串的一种重要运算 Pattern matching is an important operation.
C:串是一种数据对象和操作都特殊的线性表 String is a linear list  whose data objects and operations both special
D:空串是由空格构成的串  Empty string is a string consisting of spaces.
答案: 空串是由空格构成的串  Empty string is a string consisting of spaces.

5、 Seek the string “BAAABBBAA” ‘s feature vector, where the feature vector is defined as follows:(There is only one correct answer)数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第29张

A:{-1, 0, 0, 0, 0, 0, 0, 1, 2}
B:{-1, 0, 0, 0, 0, 1, 1, 1, 2}
C:{-1, 0, 0, 0, 0, 0, 1, 1, 2}
D:{-1, 0, 0, 0, 1, 1, 1, 1, 2}
答案: {-1, 0, 0, 0, 0, 1, 1, 1, 2}

6、 在字符{A, C, G, T}组成的DNA序列中,A和T、C和G是互补对。判断一个DNA序列中是否存在互补回文串(例如,ATCATGAT的补串是TAGTACTA,与原串形成互补回文串)。下面DNA序列中存在互补回文串的是:(多选)In the DNA sequences consisting of character {A, C, G, T}, A and T, C and G are complementary pairs. Judging whether there is a complementary palindrome sequence in a DNA sequence (e.g., ATCATGAT’s complement strings is TAGTACTA, it is complementary palindrome sequence with the original sequence). Which of the following DNA sequences have complementary palindrome string? (There are more than one answers.)

A:CTGATCAG
B:AATTAATT
C:TGCAACGT
D:CATGGTAC
E:GTACGTAC
F:AGCTAGCT
答案: CTGATCAG;
AATTAATT;
GTACGTAC;
AGCTAGCT

7、 若字符串s=“software”,则其子串个数为: If the string s = “software”, then the number of its sub-string is:
答案: 37

8、 若字符串s=”algorithm”,则其子串个数为: If the string s = “algorithm”, then the number of its sub-string is:
答案: 46

9、 设有字符串变量String A =“”,B=“MULE”,C=“OLD”,D=“MY” ; 请计算下列表达式 (3个答案本身不要出现空格,答案之间用空格分开) Assume that there is a string variable String A = “”, B = “MULE”, C = “OLD”, D = “MY”; Please calculate the following expression: (1) D+C+B(2) B.substr(3,2) (3) A.strlength()
答案: MYOLDMULE E 0

10、 一个文本串可用事先给定的字母映射表进行加密。例如,设字母映射表为:A text string can be encrypted by the given letters mapping table. For example, the letters mapping table is:数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第30张比如字符串”encrypt”被加密为”tkzwsdf”。则字符串 “algorithm”,被加密为____(Hint: 1. 答案不需要加引号 2. 系统基于字符匹配来判定答案,所以您的答案中不要出现空格)。As the string “encrypt” is encrypted as “tkzwsdf”, then the “algorithm” is encrypted as __ (Hint:1. please don’t include any quotes in your answer 2. This problem is judged by string matching, Please make sure your answer don’t contain any blanks.).
答案: neopwmfbl

11、 S=“S1S2…Sn”是一个长为n的字符串,存放在一个数组中,编程序将S改造之后输出。S = “S1S2 … Sn” is a string of length n, and stored in an array, output S after its programmable transformation.
           
 1.将S的所有第偶数个字符按照其原来的下标从大到小的次序放在S的后半部分;       1.All the even-numbered characters of S should be placed in accordance with their subscript descending order in the second half of S;2.将S的所有第奇数个字符按照其原来的下标从小到大的次序放在S的前半部分;2.All the odd-numbered characters of S should be placed in accordance with their subscript ascending order in the first half of S.例如:S=‘ABCDEFGHIJKL’,则改造后的S为‘ACEGIKLJHFDB’。则 S=’algorithm’, 改造后为__(Hint: 1. 答案不需要加引号 2. 系统基于字符匹配来判定答案,所以您的答案中不要出现空格)。For example: S = ‘ABCDEFGHIJKL’, then after the transformation S is ‘ACEGIKLJHFDB’. If S = ‘algorithm’, then after the transformation S is ____ (Hint:1. please don’t include any quotes in your answer. 2.This problem is judged by string matching, Please make sure your answer don’t contain any blanks ).
答案: agrtmhiol

12、 下列程序判断字符串s 是否对称,对称则返回1,否则返回0;如 f(“abba”)返回1,f(“abab”)返回0;Use the following procedures to determine whether the string s is symmetry, symmetry returns 1, otherwise return 0; such as f (“abab”) returns 0;int f(char s[])
{    
    int i=0,j=0;
    while(s[j])
        (1)++;
    for(j–; i < j && s[i] == s[j]; i++, j–);
    return((2)
>=(3)__);
}注:(1)和(2)和(3)三个答案之间用空格分隔,每个答案是一个字符,不要加空格                                         
答案: j i j

13、 上一题中的字符串”BAAABBBAA”,与目标”BAAABBBCDDDCCHHHHBBBAAABBBAADD”进行匹配,至少需要多少次字符匹配(提示:利用优化后的Next数组):The string in question above “BAAABBBAA” matches with “BAAABBBCDDDCCHHHHBBBAAABBBAADD”. How many times character matching will need at least? (Hint: Use “Next” arrays ):                                                                           数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第31张
答案: 31


下方是付费阅读内容:本平台商品均为虚拟商品,无法用作二次销售,不支持退换货,请在购买前确认您需要购买的资料准确无误后再购买,望知悉!


完整答案需点击上方按钮支付5元购买,所有答案均为章节测试答案,购买后上方矩形框将出现已付费的隐藏内容。


如果点击【立即购买】不能跳转,请更新一下APP版本,如百度APP可能有兼容性问题,更新版本即可正常使用,或者换一个浏览器(如UC浏览器)再试试

不知道怎么购买?点击这里查看购买教程!


为了方便下次阅读,建议在浏览器添加书签收藏本网页

添加书签方法:

1.电脑按键盘的Ctrl键+D键即可收藏本网页

2.手机浏览器可以添加书签收藏本网页

数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第71张

数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第72张


获取更多慕课答案,欢迎在浏览器访问我们的网站:http://mooc.mengmianren.com

数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第73张数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第74张

数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第75张

注:请切换至英文输入法输入域名,如果没有成功进入网站,请输入完整域名:http://mooc.mengmianren.com/


我们的公众号

打开手机微信,扫一扫下方二维码,关注微信公众号:萌面人APP

本公众号可查看各种网课答案,还可免费查看大学教材答案

点击这里,可查看公众号功能介绍

数据结构与算法(北京大学) 中国大学MOOC答案2024版100分完整版第76张


一键领取淘宝,天猫,京东,拼多多无门槛优惠券,让您购物省省省,点击这里,了解详情