QUESTION 05
What is a linear list?
2 marksAnswer
It is a finite ordered sequence of elements, where each non-end element has a logical predecessor or successor as appropriate. It need not be numerically sorted.
QUESTION 05
It is a finite ordered sequence of elements, where each non-end element has a logical predecessor or successor as appropriate. It need not be numerically sorted.
QUESTION 06
A linear list arranges elements in a logical sequence with a first and last position.
In an array list, consecutive logical positions normally occupy consecutive element positions. In a linked list, explicit links describe the sequence even when nodes are physically separate. Neither representation requires the values themselves to be sorted.
The list 10, 30, 20 has a first value 10 and last value 20. Inserting 15 after the first value produces 10, 15, 30, 20. Deleting 30 produces 10, 15, 20. The operation contract should specify whether positions are zero-based and whether duplicate values are allowed.
An empty list has no first element to read or remove. Insertion can create its first element. Deleting the only element must restore a valid empty representation. Reject invalid positions rather than writing outside storage or following a missing link.
The logical list does not prescribe one performance table. Arrays support O(1) indexed retrieval but may shift O(n) elements on insertion. Singly linked lists require O(n) indexed traversal, while head insertion uses O(1) link work. Choose and document the implementation.