877 views
0 votes
0 votes

Which data structure would be most appropriate to implement a collection of values with the following 3 characteristics

  1. Singly link list with head and tail pointer
  2. Doubly link list with only head pointer
  3. Binary tree
  4. Array

1 Answer

1 votes
1 votes

 

Ans – (A) {Given in Key} but (B) is more accurate

  • The third point indicates a spill of data in memory
  • So if there is a spill in last data element, we will have our data in last two memory bytes
  • But we have a tail that points to the last byte only
  • So, in singly link list, to access the last data we would need an extra linear traversal to second last byte ie O(n)
  • Which we could overcome by using a doubly link list

So I think Doubly should be the answer

But provided key says Singly Linked list is better, without any explanation

Related questions