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ố 4
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 đề. Trang 2/3 — câu 21–40.
Danh sách câu hỏi
int x = 9;
Node f = head;
while(f.next != tail) f = f.next;
Node q = new Node(x);
q.next = tail;
f.next = q;int h(int n)
{if (n == 0 || n==1)
return(1);
else
return(h(n-1)+h(n-2));
}Node p1,p2; p1 = p.next;
p2 = p1.next;
p.next = p2;
if(p2!=null) p2.prev=p;int fun(int n)
{if (n < 0)
return(fun(-n));
else if(n<4)
return(2);
else
return(n*fun(n/2));
}What values of n are directly handled by the stopping (base) case?
while(there are more characters in the word to read){read a character if a character is '*' then dequeue the queue
else
enqueue the character into the queue
}How the queue looks like after processing the input "Hello∗∗∗Worl***d*"?
int fun(int n)
{if(n<=0) return(1);
return(2*fun(n-2));
}What is the output when the statement:
System.out.println(fun(5));is run?
int x = 5;
Node f = head;
while(f.next != p) f = f.next;
Node q = new Node(x);
q.next = p;
f.next = q;Đáp án đúng: "7 11 6 4 5 3 9 8 2". Danh sách là 7, 11, 6, 4, 3, 9, 8, 2 và p trỏ vào nút 3. Vòng while(f.next != p) f = f.next; chạy từ head và dừng khi f là nút 4, tức nút đứng ngay trước p. Sau đó q = new Node(x) với x = 5, q.next = p nối nút mới vào trước 3, rồi f.next = q cho 4 trỏ sang 5. Nút 5 do đó nằm giữa 4 và 3, cho dãy 7, 11, 6, 4, 5, 3, 9, 8, 2. Phương án "7 11 6 4 3 5 9 8 2" là kết quả của chèn SAU p, muốn vậy phải viết q.next = p.next; p.next = q;. Phương án "7 11 6 4 3 9 8 2 5" là chèn vào cuối, cần đi tới tail chứ không dừng ở nút trước p. Phương án "7 5 11 6 4 3 9 8 2" là chèn ngay sau head, tức vòng lặp không chạy lần nào. Phương án "7 11 6 4 3 9 8 5 2" chèn trước nút cuối, không khớp với điều kiện dừng neo vào p.
void fun(int n)
{if(n > 0)
{ n = n/5;
fun(n);
System.out.print(" " + n);
}
}What is the output when the statement fun(23); is run?
int fun(int n)
{if (n < 0)
return(fun(-n));
else if(n<5)
return(2);
else
return(n*fun(n-2));
}What is the value of fun(5)?
Integer fun()
{if (isEmpty()) return(null);
Integer x = tail.info;
if (head == tail)
head = tail = null;
else
{Node p1,p; p1=null;p=head;
while(p!=tail) {p1=p;p=p.next;}
p1.next=null; tail=p1;
}
return(x);
}Specify the correct statement about the fun() method in the code above (choose the most suitable one).