update readme

master
Furkan Türkal 7 years ago
parent 901da63bee
commit ad97178a8b

@ -1,6 +1,40 @@
<h1 align="center">Linked List | SET 1 (INTRODUCTION) Source</h1>
<h1 align="center">LinkedList | SET 3 (DELETING A NODE) Source</h1>
[What It Is](#what-it-is)
## What It Is
Like arrays, LinkedList is a linear dat structure. Unlike arrays, LinkedList elements are not stored at contigous location; the elements are linked using pointers.
![Preview Thumbnail](https://raw.githubusercontent.com/Dentrax/Data-Structures-with-Go/master/linked-list-1-introduction/resources/linked-list.png)
Why Linked List ?
--------------------------
Arrays can be used to store linear data of similar types, but arrays have following limitations ;
* 1) The size of the arrays is fixed. So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to upper limit irrespective of the usage.
* 2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.
**Example**
> * ID[] = [1000, 1010, 1050, 2000, 2040]
And if we want to insert a new ID 10005, the to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000).
Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in ID[], everythink after 1010 has to moved.
Advantages Over Arrays
--------------------------
* 1) Dynamic size
* 2) Ease of insertion/deletion
Drawbacks
--------------------------
* 1) Random access is not allowed. We have to access elements sequientally starting from the first node. So we cannot do binary search with LinkedLists.
* 2) Extra memory space for a pointer is required with each element of the list.

@ -4,37 +4,29 @@
## What It Is
Like arrays, LinkedList is a linear dat structure. Unlike arrays, LinkedList elements are not stored at contigous location; the elements are linked using pointers.
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.
Let us formulate the problem statement to understand the deletion process. Given a `key`, delete the first occurrence of this key in linked list.
![Preview Thumbnail](https://raw.githubusercontent.com/Dentrax/Data-Structures-with-Go/master/linked-list-1-introduction/resources/linked-list.png)
To delete a node from linked list, we need to do following steps.
Why Linked List ?
--------------------------
* 1) Find previous node of the node to be deleted.
* 2) Changed next of previous node.
* 3) Free memory for the node to be deleted.
Arrays can be used to store linear data of similar types, but arrays have following limitations ;
> * Input: Linked List = `[7 -> 1 -> 3 -> 2]`
> * Output: Created Linked List `[2 -> 3 -> 1 -> 7]`
> * Output: Linked List after Deletion of 1: `[2 -> 3 -> 7]`
* 1) The size of the arrays is fixed. So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to upper limit irrespective of the usage.
> * Input: Position = 1, Linked List = `[8 -> 2 -> 3 -> 1 -> 7]`
> * Output: Linked List = `[8 -> 3 -> 1 -> 7]`
* 2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.
> * Input: Position = 0, Linked List = `[8 -> 2 -> 3 -> 1 -> 7]`
> * Output: Linked List = `[2 -> 3 -> 1 -> 7]`
**Example**
> * ID[] = [1000, 1010, 1050, 2000, 2040]
And if we want to insert a new ID 10005, the to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000).
**Algorithm Complexity**
Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in ID[], everythink after 1010 has to moved.
Advantages Over Arrays
--------------------------
* 1) Dynamic size
* 2) Ease of insertion/deletion
Drawbacks
--------------------------
* 1) Random access is not allowed. We have to access elements sequientally starting from the first node. So we cannot do binary search with LinkedLists.
* 2) Extra memory space for a pointer is required with each element of the list.
| Complexity | Notation |
| ----------------- |:---------:|
| `Time Complexity` | `O(1)` |

Loading…
Cancel
Save