Please answer ONLY Question 2 and 3 Draw the list to show th
Please answer ONLY Question 2 and 3
Draw the list to show the changes applied after executing EACH statement for sub-questions a and c. Use \'\'l\" in the box indicates a null pointer. 2 point each): list.next.next = list.prev; Will you lose access to any node because of the operation in step (a)? Why? Based on the result of step (a), apply the following: list.prev = list.next.next; After the steps in question (c), will you lose access to any node because of the operations in step (c)? Why? Assuming time cost is the most important thing in our decision making process, present at least ONE example scenario that can best be solved by using a doubly linked list (without the need of \"circular\", and cannot be solved as efficiently time-wise with a singly linked list), explain WHY Assuming each reference costs 1 byte, and each piece of data/info costs 1 byte as well. We have around 130 to 150 nodes to work with most of the time. Which option will be more appropriate w hen space cost is the most important thing in our decision making process: a singly linked list, or a 256 element array? Why?Solution
1.a) list.next.next points to node 3.. list.prev is a null pointer, that means it points to no node..
If we assign list.next.next=list.prev, then there will be null pointer in the next field of node 2.
b) Yes, we will be losing access to Node 3..
c) list.prev = list.next.next, points the prev filed of node 1 to node 3.
d) We wont be losing access to any node because of step c.
2. Consider travelling sales men problem.. Sales person has to chose best way to reach the destination in less time.. Consider a graph, where each node is a place in a city, and line connecting each node contains time.. If sales person has to travel from one place to another place, then he will choose the best time among the available ones.. Then after traversing to another node, if he feels that the time cost is increasing, then he can traverse back and select another node.. If it is a single linked list or circular one, then there is no chance of traversing back and choose another best path.. This is only possible in double linked list, where it maintains previous node address too.
3. When comes to space cost, its better to go with linked list rather than sequential array.. In a sequential aaray, we need to define space for all 130 to 150 nodes before inserting elements into it.. In a linked list, space will be created if any new element or node has to be added.
