Which of the following operations on a singly linked list has a time complexity of O(1)? a) accessing an element by index b) inserting an element at the start c) deleting the last... Which of the following operations on a singly linked list has a time complexity of O(1)? a) accessing an element by index b) inserting an element at the start c) deleting the last element d) searching for an element
Understand the Problem
The question is asking which operation on a singly linked list can be performed in constant time, O(1). It provides multiple options, and the question is targeting the understanding of time complexities related to linked list operations.
Answer
Inserting an element at the start.
Inserting an element at the start of a singly linked list has a time complexity of O(1).
Answer for screen readers
Inserting an element at the start of a singly linked list has a time complexity of O(1).
More Information
In a singly linked list, inserting an element at the start is done in constant time because it involves adjusting the head pointer to the new node and updating the pointer of the new node to the old head.
Tips
A common mistake is assuming that deleting the last element is O(1), but it requires traversing the list so it is O(n).
Sources
- Top Linked List MCQ (Multiple Choice Questions) - InterviewBit - interviewbit.com
- Linked List in Data Structure: Operations - Simplilearn.com - simplilearn.com
AI-generated content may contain errors. Please verify critical information