Which statements are true (select two):
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng gồm hai ý: "In a singly-linked list there is no efficient way to insert a node before a given node in the middle of the list (the action is considered efficient if it's complexity is O(1))." và "In a singly-linked list we can insert a node after a given node with time complexity O(1)". Trong danh sách liên kết đơn mỗi nút chỉ có liên kết next: với nút p cho sẵn, chèn sau p chỉ cần q.next bằng p.next rồi p.next bằng q, hai phép gán không phụ thuộc số nút nên là O(1); còn chèn trước p thì cần nút tiền nhiệm, mà không có liên kết lùi nên buộc dò lại từ head, chi phí O(n), tức không có cách làm hiệu quả theo đúng nghĩa O(1) mà đề nêu. Vì vậy "In a singly-linked list we can insert a node after a given node with time complexity O(n)" không phải ý cần chọn vì nó mô tả chi phí của việc phải dò tìm nút, trong khi p đã được cho sẵn nên không có bước dò nào, hai phép gán là xong; "In a singly-linked list we can insert a node before a given node in the middle of the list with time complexity O(1)" sai vì nó mâu thuẫn trực tiếp với việc thiếu liên kết lùi, muốn O(1) thì cấu trúc phải là danh sách liên kết đôi.
Cùng phần 1
Suppose a doubly linked list of integers is given below and p is a reference to the node with value 30 in the list (i.e. p.info=30):
(head) 7 11 6 4 30 9 8 2 (tail)
What does the list look like after the following java code snippet is run?
Node p1,p2; p1 = p.next;
p2 = p1.next;
p.next = p2;
if(p2!=null) p2.prev=p;Có lời giảiCâu hỏiSuppose a doubly linked list of integers is given below and p is a reference to the node with value 13 in the list (i.e. p.info=13):
(head) 7 11 6 4 32 13 8 2 (tail)
What does the list look like after the following java code snippet is run?
int x = 17;
Node q = new Node(x);
q.prev=null;
q.next = head;
head.prev = q;
head = q;Có lời giảiCâu hỏiSelect the statement that is most correct.
Basically, the complexity of getting an element at the middle of a singly linked lists isCó lời giảiCâu hỏiCả 64 câu của chủ đề64 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây