# Linked-List ![](https://i.imgur.com/jggEuAQ.jpg) Link to code page : (a) https://github.com/sefx5ever/SCU_DSA/blob/master/Week_1/Linked%2BList.ipynb (b) https://nbviewer.jupyter.org/github/sefx5ever/SCU_DSA/blob/master/Week_1/Linked-List.ipynb ### Function: 1. Get :Get the value of the index-th node in the linked list. If the index is invalid, return -1. 2. Add At Title :Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. 3. Add At Tail :Append a node of value val to the last element of the linked list. 4. Add At Index :Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. 5. Delete At Index :Delete the index-th node in the linked list, if the index is valid. ### Flow Description: * #### Singly Linked List ![](https://i.imgur.com/Ndlg5h7.png) First of all, you can try to imagine that Node as a container which include a data and a reference to the next node. Then, the last node will point to null. The entry point into a linked list is called the head of the list. * #### Doubly Linked List ![](https://i.imgur.com/hBuz0bU.png) A doubly linked list contain two references, one to the next and another to previous node. ### Test(Singly Link List): ![](https://i.imgur.com/TC7sdQt.png) ### Extra Description: * #### A linked list is a dynamic data structure. The number of nodes in a list is not fixed and can grow and shrink on demand. Any application which has to deal with an unknown number of objects will need to use a linked list. * #### Complexity | Data Structure | Time Complexity[Average] | Time Complexity[Worst] | | ------------- | ------------- | ------------- | | Singly Link List | O(n) | O(1) | | Doubly Link List | O(n) | O(1) | * #### Time Taken In LeetCode ![](https://i.imgur.com/Co99URe.png) ### References: * https://www.youtube.com/watch?v=WwfhLC16bis&t=779s * https://www.youtube.com/watch?v=njTh_OwMljA&t=184s * https://www.youtube.com/watch?v=Rs1KPyb9fHY&t=11s * https://www.youtube.com/watch?v=0xoYNbVTiSE&t=220s