A warm hello to all the readers!

In the last post, we talked about the origin of linked list data structure. There are variations in linked list as well. In this post, we will understand the first variation or type which is called Singly Linked List.

The singly linked list is actually the same as the basic concept of linked list data structure. The elements are stored in non continuous memory locations. Each element contains two values. One is the actual value of the element. Second is the pointer or memory address of the next element.

And a sample singly linked list is represented as:

50x5004
Node1 at address x5002

28x5008
Node2 at address x5004

30null
Node3 at address x5008

Node1 is pointing to Node2 and Node2 is pointing to Node3. Node3 is the last node and does not point to any memory address. Therefore, pointer is null.

The singly linked list means that the list can be traversed in a single direction only. We can go from Node1 to Node2 and then Node3. We cannot travel back from Node3 to Node2 and so on.

What Are Singly Linked List Operations?

Let us now talk about different operations that can be performed on singly linked list.

  1. The item can be accessed
  2. A new item can be inserted in the beginning, end or anywhere in between the list
  3. Any item can be deleted
  4. Any item can be searched by traversing the list

What Is The Time Complexity Of Singly Linked List?

Now we know the different operations that can be performed on the singly linked list. We shall now see what is the time complexity of each operation.

  1. Accessing element – This takes O(n) time because each element has to be traversed to see memory address of next element
  2. Inserting element – This takes O(n) time since in worst case if inserting element in middle of the list, then this requires traversing the list.
  3. Deleting element – This again takes O(n) time since in worst case if inserting element in middle of the list, then this requires traversing the list.
  4. Searching element – This also takes O(n) time since it requires (n) unknown number of iterations over the elements of the list in order to search a particular value

Similar Posts

Error: GraphComment couldn't be load because your settings are invalid. Please visit your admin panel and go to the GraphComment section and enter a valid website URL/ID.