Which of the following operations has a time complexity of O(n) in a singly link
Practice Questions
Q1
Which of the following operations has a time complexity of O(n) in a singly linked list?
Insertion at head
Insertion at tail
Deletion at head
Accessing an element by index
Questions & Step-by-Step Solutions
Which of the following operations has a time complexity of O(n) in a singly linked list?
Step 1: Understand what a singly linked list is. It is a data structure where each element (node) points to the next one.
Step 2: Know that accessing an element by index means you want to find the element at a specific position in the list.
Step 3: Realize that to access an element by index in a singly linked list, you have to start from the first element and go through each node one by one until you reach the desired index.
Step 4: Count how many nodes you might need to go through. In the worst case, if the index is at the end of the list, you will have to go through all n nodes.
Step 5: Conclude that this traversal takes time proportional to the number of nodes, which is O(n).