Please answer the following question and explain your answer
Please answer the following question, and explain your answer
A Assume each data element costs 1 byte, each reference/pointer costs 1 byte. Comparing with array that can hold 300 elements, which of the following solution will be the best when space consumption is the key determining factor? Array is always the best solution when space consumption is the key determining factor A singly linked list when we have less than 150 nodes in the list A doubly linked list when we have more than 100 nodes in the list Any types of the list will cost the same amount of spaceSolution
Answer is B
A singly linked list when we have less than 150 nodes in the list as the single linked list consists of the nodes which has 2 parts(1.data 2.next). The node consists of the data or the value. the next node consists of the pointer to the next stored value. the choice B says less than 150 nodes. If the single linked list consists of 150 nodes then the space consumption would be 2*150=300bytes according to the question. But the specified is less than 150 nodes, therefore the space consumption must be less than 300.
now the cost for 300 elements in the array would be 301(300bytes for elements 1 byte for pointer).Therefore the choice B is the correct answer. But not A.
Doubly linked list consists of nodes with 3 parts therefore it would be more than 301.
for further queries kindly get back
