判断题
1.In a singly linked list of N nodes, the time complexities for query and insertion are O(1) and O(N), respectively.
查找是O(N),因为需要沿着next指针找下去。而插入是O(1),只需要改变指针就行了。
2.If N numbers are stored in a singly linked list in increasing order, then the average time complexity for binary search is O(logN).
因为链表不支持随机存取,而O(logN)的算法严重依赖于随机存取,所以不可能完成。
3.If keys are pushed onto a stack in the order abcde
, then it's impossible to obtain the output sequence cedab
.
a在b的前面意味着a如果不在一开始取出就不能在b之前被取出,所以是不可能的。
4.An algorithm to check for balancing symbols in an expression uses a queue to store the partial expression.
balancing symbols指的是一组匹配的符号,类似于圆括号,花括号,方括号。可见这道题的意思是求解逆波兰表达式,使用stack而非queue。
5.To sort N distinct records by bubble sort, the number of record swaps must reach its maximum when the original sequence is almost in sorted order.
冒泡排序的record swaps取决于逆序对的数量,对于一个已经排序过的序列,逆序对的数量可以是0或者最大,逆序对的数量可能最大也可能最小。
6.To sort N records by simple selection sort, the numbers of comparisons and record movements are O(N2) and O(N), respectively.
比较次数的计算:(n-1)+(n-2)+...+2+1。共用n2/2次。移动只在一轮比较完成后,所以就算每次都需要移动,一共也才(n-1)次,所以比较可以看作O(N2),移动可以看作O(N)。
7.(neuDS)算法必须有输出,但可以没有输入。
算法有0个或多个输入,以刻画运算对象的初始情况;算法有一个或多个输出,以反映对输入数据加工后的结果。
8."Circular Queue" is defined to be a queue implemented by a circularly linked list or a circular array.
循环队列是一个抽象的概念,不局限于实现方式。
9.对于一个随机算法,其最坏情况下的运行时间等于运行时间期望值的常数倍。
虽然我们希望如此,因为这会使算法比较稳定,但大多数算法的运行时间期望值是最优和最差的情况的折中。
10.For a sequentially stored linear list of length N, the time complexities for query and insertion are O(1) and O(N), respectively.
顺序存储的线性表支持随机存取,所以查询的时间是常数时间,但插入需要把后面每一个元素的位置都进行调整,所以是线性时间。
11.The Fibonacci number sequence {FN} is defined as: F0=0, F1=1, FN=FN-1+FN-2, N=2, 3, .... The space complexity of the function which calculates FN recursively is O(logN).
为了求FN,需要从F0到FN的值,需要O(N)。
12.斐波那契数列FN的定义为:F0=0, F1=1, FN=FN-1+FN-2, N=2, 3, …。用递归函数计算FN的空间复杂度是O(logN)。
13.(neuDS)数据的物理结构是指数据在计算机中的实际存储形式。
物理结构和计算机的硬件直接相关。
14.If keys are pushed onto a stack in the order {1, 2, 3, 4, 5}, then it is impossible to obtain the output sequence {3, 4, 1, 2, 5}.
FIFO结构。
15.If the most commonly used operations are to visit a random position and to insert and delete the last element in a linear list, then sequential storage works the fastest.
频繁地对最后一个元素查删,顺序表完全可以胜任。
16.For the following piece of code
if ( A > B ){
for ( i=0; i<N*2; i++ )
for ( j=N*N; j>i; j-- )
C += A;
}
else {
for ( i=0; i<N*N/2; i++ )
for ( j=N; j>i; j-- )
for ( k=0; k<N*100; k++)
C += B;
}
the lowest upper bound of the time complexity is O(N5)
最多是O(N4)。
17.If keys are pushed onto a stack in the order abcde
, then it's impossible to obtain the output sequence cdabe
.
18.If N numbers are stored in a doubly linked list in increasing order, then the average time complexity for binary search is O(logN).
19.Given the input sequence onto a stack as {1, 2, 3, ..., N}. If the first output is i, then the j-th output must be j-i-1.
20.用动态规划而非递归的方法去解决问题时,关键是将子问题的计算结果保存起来,使得每个不同的子问题只需要被计算一次。子问题 的解可以被保存在数组或哈希散列表中。
21.Let S be the set of activities in Activity Selection Problem. The greedy rule of "collecting the activity that starts the latest" is correct for finding a maximum-size subset of mutually compatible activities of S.
22.(neuDS_C++)空串与空格串是相同的。
23.(neuDS)线性表的逻辑顺序和存储顺序总是一致的。
24.(nueDS_C++)如果一个串中的所有字符均在另一串中出现,则说前者是后者的子串。
25.(neuDS)单链表不是一种随机存取的存储结构。
26.设只包含根结点的二叉树高度为0,则高度为k的二叉树最小结点数为k+1。
27.二叉树通常有顺序存储结构和链式存储结构。
28.存在一棵总共有2016个结点的二叉树,其中有16个结点只有一个孩子。
29.具有10个叶结点的二叉树中,有9个度为2的结点。
30.An algorithm to check for balancing symbols in an expression uses a stack to store the symbols.
选择题
1.If a linear list is represented by a linked list, the addresses of the elements in the memory:
B.may or may not be consecutive
C.must be consecutive for part of the elements
D.must be nonconsecutive
2.If the most commonly used operations are to insert a new element after the last element, and to delete the first element in a linear list, then which of the following data structures is the most efficient?
B.singly linked circular list with a tail pointer
C.singly linked circular list with a head pointer
D.doubly linked list
3.When is the linked list structure suitable for representing a linear list L?
B.frequently change the key values of the nodes in L
C.L contains large amount of nodes
D.the structure of the nodes in L is complicated
4.The best "worst-case time complexity" for any algorithm that sorts by comparisons only is:
B.O(N)
C.O(NlogN)
D.O(N 2)
5.To sort N distinct elements in descending order by bubble sort, under which condition of the elements that the method will make the most number of swaps?
B.pre-sorted in descending order
C.unsorted
D.almost sorted
6.To sort N elements by simple selection sort, the numbers of comparisons and movements are:
B.O(N), O(logN)
C.O(logN), O(N 2)
D.O(NlogN), O(NlogN)
7.Use simple insertion sort to sort 10 numbers from non-decreasing to non-increasing, the possible numbers of comparisons and movements are:
B.100, 54
C.54, 63
D.45, 44
8.Since the speed of a printer cannot match the speed of a computer, a buffer is designed to temperarily store the data from a computer so that later the printer can retrieve data in order. Then the proper structure of the buffer shall be a:
B.queue
C.tree
D.graph
9.Represent a queue by a singly linked list. Given the current status of the linked list as 1->2->3
where x->y
means y
is linked after x
. Now if 4
is enqueued and then a dequeue is done, the resulting status must be:
B.2->3->4
C.4->1->2
D.the solution is not unique
10.Use binary search to find a number from 100 sorted numbers, the worst-case number of comparisons is:
B.10
C.50
D.99
11.Given the rucurrent equations for the time complexity of a program as: T(1)=1, and T(N)=2T(N/2)+N. Then the time complexity must be:
B.O(N)
C.O(NlogN)
D.O(N 2)
为了获得T(N),需要计算递归等式logN次,2T(N/2)计算logN次后就等于N,N计算logN次后等于NlogN,两边取大的一方,最终的结果就是NlogN。
12.The recurrent equations for the time complexities of programs P1 and P2 are:
- P1: T(1)=1, T(N)=T(N/2)+1;
- P2: T(1)=1, T(N)=2T(N/2)+1;
Then the correct conclusion about their time complexities is:
B.O(logN) for P1, and O(N) for P2
C.they are both O(N)
D.O(logN) for P1, and O(NlogN) for P2
P1的加号左边经过logN次递归等式计算恒等于1,而右边每次递归等式都加1,经过logN次计算最后为logN,两边取大是logN;
P2加号的左边经过logN次递归等式计算是N,右边每次递归等式都加1,经过logN次计算最后为logN,两边取大总体为N。
13.For a sequentially stored linear list of length N, the time complexities for query and insertion are:
B.O(1), O(N)
C.O(N), O(1)
D.O(N), O(N)
14.For a sequentially stored linear list of length N, which of the following operations has the time complexity O(1)?
B.insert a new node after the i-th (1≤i≤N) node
C.delete the i-th (1≤i≤N) node
D.sort the N nodes in increasing order
15.切原木问题:给定一根长度为N米的原木;另有一个分段价格表,给出长度L=1,2,...,M对应的价格PL。要求你找出适当切割原木分段出售所能获得的最大收益RN。例如,根据下面给出的价格表,若要出售一段8米长的原木,最优解是将其切割为2米 和6米的两段,这样可以获得最大收益R8=P2+P6=5+17=22。而若要出售一段3米长的原木,最优解是 根本不要切割,直接售出。
Length L | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
Price PL | 1 | 5 | 8 | 9 | 10 | 17 | 17 | 20 | 23 | 28 |
下列哪句陈述是错的?
B.若N≤M,则有R N=max{P N,max 1<=i<N{R i+R N-i}}
C.若N>M,则有R N=max 1<=i<N{R i+R N-M}
D.算法的时间复杂度是O(N 2)
16."二叉树为空"意味着二叉树() 。
B.根结点没有子树
C.不存在
D.没有结点
17.栈和队列的共同点( )。
B.都是后进先出
C.只允许在端点处插入和删除元素
D.没有共同点
18.广义表是一种()数据结构。
B.递归的
C.树型
D.图状
19.若串S="software",其子串的数目是
B.37
C.36
D.9
20.What is the major difference among lists, stacks, and queues?
B.Stacks and queues are lists with insertion/deletion constraints
C.Lists and queues can be implemented using circularly linked lists, but stacks cannot
D.Lists are linear structures while stacks and queues are not
21.线性表是一个()。
B.有限序列,不能为空
C.无限序列,可以为空
D.无限序列,不能为空
22.Given a 12×12 symmetric matrix M. If the upper triangular entries mi,j (1≤i≤j≤12) of M are stored row by row in a 1-dimentional array N
(in C programming language). What is the index of m6,6 in N
?
B.51
C.55
D.66
23.阅读下列程序,其功能是()。
typedef struct {
ElemType *list;
int size;
intMaxSize;
}SeqList;
void fun1(SeqList&L) {
inti, j;
ElemType temp;
for (i=0, j= L.sise-1; i<j; i++, j--) {
temp=L.list[i];
L.list[i]=L.list[j];
L.list[j]=temp;
}
}
B.将链表原地逆置
C.将顺序表首尾元素对换
D.将链表首尾元素对换
24.If the pushing sequence of a stack is {1, 2, 3, ..., N} and the first number being popped out is i, then the j-th number being popped must be:
B.i?j
C.j?i?1
D.cannot be determined
25.In-order traversal of a binary tree can be done iteratively. Given the stack operation sequence as the following:
push(1), push(2), push(3), pop(), push(4), pop(), pop(), push(5), pop(), pop(), push(6), pop()
Which one of the following statements is TRUE?
B.1 is the parent of 5
C.6 is the root
D.None of the above
26.Given an empty stack S and an empty queue Q. Push elements {1, 2, 3, 4, 5, 6, 7} one by one onto S. If each element that is popped from S is enqueued onto Q immediately, and if the dequeue sequence is {3, 2, 6, 5, 7, 4, 1}, then the minimum size of S must be:
B.3
C.4
D.5
27.What is NOT a feature of a linked list?
B.easy for random query
C.no pre-estimation of the size is necessary
D.the space taken is proportional to the size of the list
28.Suppose that an array of size m
is used to store a circular queue. If the front position is front
and the current size is size
, then the rear element must be at:
B.`front+size-1`
C.`(front+size)%m`
D.`(front+size-1)%m`
29.Suppose that enqueue is allowed to happen at both ends of a queue, but dequeue can only be done at one end. If elements are enqueued in the order {a, b, c, d, e}, the impossible dequeue sequence is:
B.d b a c e
C.e c b a d
D.d b c a e
30.依次在初始为空的队列中插入元素a,b,c,d以后,紧接着做了两次删除操作,此时的队头元素是( )。
B.b
C.c
D.d