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 đề. Trang 3/3 — câu 41–50.
Danh sách câu hỏi
deletepeekdequeueremovelist (i.e. p.info=19):(head) 7 21 6 4 23 19 8 12 (tail) What does the list look like after the following java code snippet is run?
int x = 5;
Node f = p.prev; // prev is a link to predecessor node
Node q = new Node(x); // Create new node with value x
q.prev = f; q.next = p;
f.next = q; p.prev = q;while(there are more characters in the word to read){read a character if a character is '*' then pop the stack
else
push the character into the stack
}
while(the stack is not empty)pop and write the poped character to the screen What is written to the screen for the input "FileComp**ress*ion***" ?
seroCeliseroCeliFseroCelFiseroCeliFnFilreionint x = 13;
Node f = head;
while(f.next != p) f = f.next;
Node q = new Node(x);
q.next = p;
f.next = q;void inOrder(Node p)
{ inOrder(p.left); visit(p); inOrder(p.right); }void inOrder(Node p)
{ if (p == null) { inOrder(p.left); visit(p); inOrder(p.right); }
}void inOrder(Node p)
{ if (p != null) { visit(p); inOrder(p.left); inOrder(p.right); }
}void inOrder(Node p)
{ if (p != null) { inOrder(p.left); visit(p); inOrder(p.right); }
}Đáp án đúng: "
void inOrder(Node p) {
if (p != null) {
inOrder(p.left);
visit(p);
inOrder(p.right);
}
}". Duyệt giữa cần đúng hai điều: trình tự con trái, thăm gốc, con phải; và điều kiện dừng khi gặp cây rỗng, vì mỗi lá vẫn gọi tiếp vào hai liên kết null. Bản này kiểm p khác null trước rồi mới đi xuống nên đệ quy chắc chắn kết thúc. Phương án "
void inOrder(Node p) {
inOrder(p.left);
visit(p);
inOrder(p.right);
}" không có điểm dừng nào, lời gọi đầu tiên đã lao xuống bên trái mãi và sinh lỗi truy cập null hoặc tràn ngăn xếp. Phương án "
void inOrder(Node p) {
if (p == null) {
inOrder(p.left);
visit(p);
inOrder(p.right);
}
}" đảo ngược điều kiện: với cây không rỗng nó chẳng làm gì, còn khi p là null nó lại đọc p.left nên lỗi ngay. Phương án "
void inOrder(Node p) {
if (p != null) {
visit(p);
inOrder(p.left);
inOrder(p.right);
}
}" dừng đúng nhưng thăm gốc trước hai con, đó là duyệt trước, và trên cây tìm kiếm nhị phân nó không cho dãy tăng dần.
while(there are more characters in the word to read){read a character if a character is '*' then dequeue and write the dequeued character to the screen
else
enqueue the character into the queue
}What is written to the screen for the input ""Go*odA**fter****Noo***n" ?
oAdoretfooGoodAfteroodAfterooGoodAfterN