From ca24fc0f20f0cc8f4a0f2e7372fadb1e2be47f3c Mon Sep 17 00:00:00 2001 From: Aadit Kamat Date: Fri, 25 Sep 2020 16:54:54 +0800 Subject: [PATCH] contents: update linked list insertion and deletion explanation (#175) --- contents/algorithms/linked-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/algorithms/linked-list.md b/contents/algorithms/linked-list.md index f369172c..1fc9c203 100644 --- a/contents/algorithms/linked-list.md +++ b/contents/algorithms/linked-list.md @@ -5,7 +5,7 @@ title: Linked List ## Notes -Like arrays, linked lists are used to represent sequential data. The benefit of linked lists is that insertion and deletion from anywhere in the list is O(1) whereas in arrays the following elements will have to be shifted. +Like arrays, linked lists are used to represent sequential data. The benefit of linked lists is that insertion and deletion of a node in the list (given its location) is O(1) whereas in arrays the following elements will have to be shifted. Adding a dummy node at the head and/or tail might help to handle many edge cases where operations have to be performed at the head or the tail. The presence of dummy nodes essentially ensures that operations will never have be done on the head or the tail, thereby removing a lot of headache in writing conditional checks to dealing with null pointers. Be sure to remember to remove them at the end of the operation.