Of the three variations of linked lists (circular, with header and trailer nodes
ID: 3664831 • Letter: O
Question
Of the three variations of linked lists (circular, with header and trailer nodes, and doubly linked), which would be most appropriate for each of the following applications and why?
1. You want to search a list for a key and return the keys of the two elements that come before it and the keys of the two elements that come after it.
2. A text file contains integer elements, one per line, sorted from smallest to largest. You must read the values from the file and create a sorted linked list containing the values.
3. A list is short and frequently becomes empty. You want a list that is optimal for inserting an element into the empty list and deleting the last element from the list
Explanation / Answer
Answers):
1. Since the two elements that comes before and the keys of the two elements that come after has to be returned, DOUBLY Linked list will be most appropriate for this as doubly linked list has links for both after and befor nodes.
2. HEADER and TRAILER nodes linked list will be most appropriate for this as the integer elements in the text files are already sorted, therefore, when the linked list will be created after reading from the text file it will also be sorted and no extra effort will be needed. It will be just reading line from the text file and inserting into the linked list node.
3. CIRCULAR Linked list will be most appropriate for this. Circular linked list will be otimal for insertion and deletion operations taken together.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.