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?
  1. Insertion at head
  2. Insertion at tail
  3. Deletion at head
  4. 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).
No concepts available.
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely