Skip to content

Commit 3b809c5

Browse files
committed
update readme & added image
1 parent 8a2d1c2 commit 3b809c5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<h1 align="center">LinkedList Deleting a Node Source</h1>
2+
3+
[What It Is](#what-it-is)
4+
5+
## What It Is
6+
7+
We have discussed **[Linked List Introduction](https://github.com/Dentrax/Data-Structures-with-Go/tree/master/linked-list-1-introduction)** and **[Linked List Insertion](https://github.com/Dentrax/Data-Structures-with-Go/tree/master/linked-list-2-inserting-a-node)** in previous posts on singly linked list.
8+
Let us formulate the problem statement to understand the deletion process. Given a `key`, delete the first occurrence of this key in linked list.
9+
10+
To delete a node from linked list, we need to do following steps.
11+
12+
* 1) Find previous node of the node to be deleted.
13+
* 2) Changed next of previous node.
14+
* 3) Free memory for the node to be deleted.
15+
16+
> * Input: Linked List = `[7 -> 1 -> 3 -> 2]`
17+
> * Output: Created Linked List `[2 -> 3 -> 1 -> 7]`
18+
> * Output: Linked List after Deletion of 1: `[2 -> 3 -> 7]`
19+
20+
> * Input: Position = 1, Linked List = `[8 -> 2 -> 3 -> 1 -> 7]`
21+
> * Output: Linked List = `[8 -> 3 -> 1 -> 7]`
22+
23+
> * Input: Position = 0, Linked List = `[8 -> 2 -> 3 -> 1 -> 7]`
24+
> * Output: Linked List = `[2 -> 3 -> 1 -> 7]`
25+
26+
![Preview Thumbnail](https://raw.githubusercontent.com/Dentrax/Data-Structures-with-Go/master/linked-list-3-deleting-a-node/resources/deleting-a-node.png)
27+
28+
**Algorithm Complexity**
29+
30+
| Complexity | Notation |
31+
| ----------------- |:---------:|
32+
| `Time Complexity` | `O(n)` |
Loading

0 commit comments

Comments
 (0)