In the worst case, the number of comparisons needed to search a single linked list of length for a given element is
View worked solution
Answer: D
In a singly linked list, elements are accessed sequentially starting from the head node because there is no direct indexing (random access) available.
To search for a target element in a singly linked list of length :
- Best Case: The element is at the first position (head of the list), requiring comparison.
- Average Case: The element is located somewhere in the middle, requiring approximately comparisons on average.
- Worst Case: The element is either at the very end of the list (the -th node) or is not present in the list at all. In this case, we must traverse and compare all elements.
Thus, the number of comparisons needed in the worst case is .
Free practice · Your answers on this page are not saved.
