Câu hỏi: CSD201 Cấu trúc dữ liệu và giải thuật – Bộ ôn tập cuối kỳ số 2
50 câu trắc nghiệm kèm lời giải của môn CSD201 - Cấu trúc dữ liệu và giải thuật, xếp đúng thứ tự trong đề.
Danh sách câu hỏi
A recursive method is a method that invokes itself directly or indirectly. For a recursive method to terminate
there must be one or more base cases. f(n) = 2;
2. if n >1 then
f(n) = f(n-1) + 2f(n-2)What is the value of f(4) ?
Hash function h(x) is a function which transforms a particular key x, be it a string, number, record, or the
like, into non-negative integer.Hash function h(x) is a function which transforms a particular key x, be it a string, number, record, or the
like, into an index i = h(x) in the table T, where T[i] is used for storing an item having key x or its address.Hash function h(x) is a function which transforms a particular key x (string, or number) into an index i =
h(x) in the table T, where T[i] is used for storing an item having key x or its address.Hash function h(x) is a function which transforms a particular key x, be it a string, number, record, or the
like, into a positive integer.int binarySearch(int [] a, int x, int low, int high)
{ int t, k;
if(low > high) return( -1);
k = (low + high) / 2;
if(a[k] == x) return(k);
if(x<a[k]) return(binarySearch(a,x,low,k-1);
else return(binarySearch(a,x,k+1,high);
}Suppose the array a is given by the statement:
int [] a = {2,4,6,8,10,12,14, 16};For the call binarySearch(a,7,2, 5), how many calls to this will be made, including the original call?
while(S is not empty){ch = top element of the stack S if ch is isolated then remove it from the stack and put it to E
elseselect the first vertex Y (by alphabet order), which is adjacent to ch,push Y to S and remove the edge (ch,Y) from the graph
}the last array E obtained is an Euler cycle of the graph Suppose a multigraph G is given below (view picture). Which of the followings is the Euler cycle from the vertex A, created by above algorithm?
deletepeekpopremovelist (i.e. p.info=29):(head) 17 11 6 4 3 29 8 2 (tail) What does the list look like after the following java code snippet is run?
int x = 5;
Node p1, p2;
p1 = new Node(x);
p2 = p.next;
p.next = p1; p1.prev = p;
p1.next = p2; p2.prev = p1;Node q = new Node(x);
q.next = null;tail.next = new Node(x);
tail.next = null;
tail = tail.next;Node q = new Node(x);
q.next = null;
tail.next = q;
tail = q;tail.next = new Node(x);
tail.next.next = null;Đáp án đúng: "Node q = new Node(x); q.next = null; tail.next = q; tail = q;". Chèn vào cuối danh sách liên kết đơn cần đủ ba việc: tạo nút mới với next là null để nó thực sự là nút cuối, cho nút cuối hiện tại trỏ tới nó, và cập nhật tail để biến này tiếp tục chỉ đúng nút cuối. Đoạn mã này làm cả ba theo thứ tự an toàn vì nó gắn q vào sau tail cũ trước khi đổi tail. Phương án "Node q = new Node(x); q.next = null;" chỉ tạo nút rồi bỏ đó, không nút nào trong danh sách trỏ tới q nên danh sách không dài thêm. Phương án "tail.next = new Node(x); tail.next = null; tail = tail.next;" gán tail.next hai lần, lần sau ghi null lên chính liên kết vừa tạo nên nút mới bị mất, rồi tail nhận null và không còn chỉ vào nút nào. Phương án "tail.next = new Node(x); tail.next.next = null;" gắn được nút mới nhưng quên cập nhật tail, nên lần chèn sau lại gắn vào nút kề cuối và ghi đè mất nút vừa thêm.