判斷題
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