26. Reeall our implemeutation of a doubly-liskoed list (DLList) protected class
ID: 3596352 • Letter: 2
Question
26. Reeall our implemeutation of a doubly-liskoed list (DLList) protected class Node f ode nezt, prer: public class ou.ist extends AbstractSequentialListeT> protected Node duey protected int n Explain tho role of the duney node. In particular, if our list is noncmpty,then what are dussy next and dumay-prev? (a) dumay.sext and dumay-prey are both the first node in the list (b) dumay.next and dumay-prer are both the last mode in the list c) dumay.sext is the last node in the list aad dumey prow is the irst node in the list aumay.ext is the first node in the list and dumny.prev is the last toude in the lest (e) Noue of the above is true 27. Consider the orrentiss of the following two methods that adda node before the Dode P in a DLList. protected Node add(Node u, Node p) f .next p: prev·p. prev ; a . next , prev . u; a.prew.Bextu recurn protected Node add(Node u, Node p) f .next- p a.next prevu return u The first method is correct (b) The second method correct (c) Neither mcthod is cormect d) Both acthods are correct (e) Both (e) and (d) 28. What is the running-time of add(i,x) and retove(i) in DLList? (a) O(1+) and O(1 +4), respectively (b) O(1) and O(1 +siz)-4), respectively (c) 0(1 + ize()-1) and 0(1), respectively 0(1 + min{i.size()-1)) and 0(1 + min{1,8ize()-1)), respectively (e) O(l) and Ol+size) -), respectivelyExplanation / Answer
26) Dummy node will be pointed as last node, i.e. dummy->prev is last node and dummy->next will be null, because it is dll not circular linked list dummy->next can't be first node. so none of the above is true.
27) method 1 is correct as the node u should be attached first to the exixting list. and existing list connections should be modified next. but in method 2, in 3rd statement u.prev will be u only as p.prev is already set to u. so connections will be wrong.
28) time complexity of addition and removal of node in linked list will be same, so option c is correct. And also depends on where we are adding and removing. if it is first O(1) only, if it is at last O(n), at middle , then it is average case, so O(i+min(i.size()-i) will be time complexity
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.