From 76fadaa2fd3edf6d17dd96e3d9d1aa13dd88de43 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 12:09:47 +0530 Subject: [PATCH 01/18] this is the new change --- contrib/Linklist/linklist.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 contrib/Linklist/linklist.md diff --git a/contrib/Linklist/linklist.md b/contrib/Linklist/linklist.md new file mode 100644 index 0000000..e69de29 From 05e14ba89825fe857c9b3ec1333e0f288161d83e Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 13:26:15 +0530 Subject: [PATCH 02/18] New change --- contrib/{Linklist/linklist.md => ds-algorithms/Linked-list.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/{Linklist/linklist.md => ds-algorithms/Linked-list.md} (100%) diff --git a/contrib/Linklist/linklist.md b/contrib/ds-algorithms/Linked-list.md similarity index 100% rename from contrib/Linklist/linklist.md rename to contrib/ds-algorithms/Linked-list.md From b2a16691059d9b0cff7b544a779299b1722708b1 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:09:10 +0530 Subject: [PATCH 03/18] this is commit --- contrib/ds-algorithms/Linked-list.md | 181 +++++++++++++++++++++++++++ contrib/ds-algorithms/index.md | 1 + 2 files changed, 182 insertions(+) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index e69de29..d3d7ec1 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -0,0 +1,181 @@ +# Linked List Data Structure + +Link list is a linear data Structure which can be defined as collection of objects called nodes that are randomly stored in the memory. +A node contains two types of metadata i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory. +The last node of the list contains pointer to the null. + +## Why use linked list over array? + +From the beginning, we are using array data structure to organize the group of elements that are stored individually in the memory. +However, there are some advantage and disadvantage of array which should be known to decide which data structure will used throughout the program. + +limitations + +1. The size of array must be known in advance before using it in the program. +2. Increasing size of the array is a time taking process. It is almost impossible to expand the size of the array at run time. +3. All the elements in the array need to be contiguously stored in the memory. Inserting any element in the array needs shifting of all its predecessors. + +So we introduce a new data structure to overcome these limitations. + +Linked list is used because, +1. It allocates the memory dynamically. All the nodes of linked list are non-contiguously stored in the memory and linked together with the help of pointers. +2. Sizing is no longer a problem since we do not need to define its size at the time of declaration. List grows as per the program's demand and limited to the available memory space. + +Let's code something + +The smallest Unit: Node + +class Node: + def __init__(self, data): + self.data = data # Assigns the given data to the node + self.next = None # Initialize the next attribute to null + +Now, we will see the types of linked list. + +There are mainly four types of linked list, +1. Singly Link list +2. Doubly link list +3. Circular link list +4. Doubly circular link list + + +## 1. Singly linked list. + +Simply think it is a chain of nodes in which each node remember(contains) the addresses of it next node. + +### Creating a linked list class + +class LinkedList: + def __init__(self): + self.head = None # Initialize head as None + +### Inserting a new node at the beginning of a linked list + + def insertAtBeginning(self, new_data): + new_node = Node(new_data) # Create a new node + new_node.next = self.head # Next for new node becomes the current head + self.head = new_node # Head now points to the new node + +### Inserting a new node at the end of a linked list + + def insertAtEnd(self, new_data): + new_node = Node(new_data) # Create a new node + if self.head is None: + self.head = new_node # If the list is empty, make the new node the head + return + last = self.head + while last.next: # Otherwise, traverse the list to find the last node + last = last.next + last.next = new_node # Make the new node the next node of the last node + +### Inserting a new node at the middle of a linked list + + def insertAtPosition(self, data, position): + new_node = Node(data) + if position <= 0: #check if position is valid or not + print("Position should be greater than 0") + return + if position == 1: + new_node.next = self.head + self.head = new_node + return + current_node = self.head + current_position = 1 + while current_node and current_position < position - 1: #Iterating to behind of the postion. + current_node = current_node.next + current_position += 1 + if not current_node: #Check if Position is out of bound or not + print("Position is out of bounds") + return + new_node.next = current_node.next #connect the intermediate node + current_node.next = new_node + +### Printing the Linked list + + def printList(self): + temp = self.head # Start from the head of the list + while temp: + print(temp.data,end=' ') # Print the data in the current node + temp = temp.next # Move to the next node + print() # Ensures the output is followed by a new line + + +Lets complete the code and create a linked list. + +Connect all the code. + +if __name__ == '__main__': + llist = LinkedList() + + # Insert words at the beginning + llist.insertAtBeginning(4) # <4> + llist.insertAtBeginning(3) # <3> 4 + llist.insertAtBeginning(2) # <2> 3 4 + llist.insertAtBeginning(1) # <1> 2 3 4 + + # Insert a word at the end + llist.insertAtEnd(10) # 1 2 3 4 <10> + llist.insertAtEnd(7) # 1 2 3 4 10 <7> + + #Insert at a random position + llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7 + # Print the list + llist.printList() + + + + output: + 1 2 3 9 4 10 7 + + +### Deleting a node from the beginning of a linked list +check the list is empty otherwise shift the head to next node. + +def deleteFromBeginning(self): + if self.head is None: + return "The list is empty" # If the list is empty, return this string + self.head = self.head.next # Otherwise, remove the head by making the next node the new head + +### Deleting a node from the end of a linked list + +def deleteFromEnd(self): + if self.head is None: + return "The list is empty" + if self.head.next is None: + self.head = None # If there's only one node, remove the head by making it None + return + temp = self.head + while temp.next.next: # Otherwise, go to the second-last node + temp = temp.next + temp.next = None # Remove the last node by setting the next pointer of the second-last node to None + + +### Search in a linked list + +def search(self, value): + current = self.head # Start with the head of the list + position = 0 # Counter to keep track of the position + while current: # Traverse the list + if current.data == value: # Compare the list's data to the search value + return f"Value '{value}' found at position {position}" # Print the value if a match is found + current = current.next + position += 1 + return f"Value '{value}' not found in the list" + + + + + + + + + + + + + + + + + + diff --git a/contrib/ds-algorithms/index.md b/contrib/ds-algorithms/index.md index 666bcfd..4b6e20d 100644 --- a/contrib/ds-algorithms/index.md +++ b/contrib/ds-algorithms/index.md @@ -8,3 +8,4 @@ - [Searching Algorithms](searching-algorithms.md) - [Greedy Algorithms](greedy-algorithms.md) - [Dynamic Programming](dynamic-programming.md) +- [Linked list](Linked-list.md) From d2a25f16cca049ed1f1b06cd5d25a677144f4ea4 Mon Sep 17 00:00:00 2001 From: Vinay Sagar <64737008+vinay-sagar123@users.noreply.github.com> Date: Sun, 26 May 2024 14:13:10 +0530 Subject: [PATCH 04/18] Update Linked-list.md new change --- contrib/ds-algorithms/Linked-list.md | 39 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index d3d7ec1..a660b1c 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -104,28 +104,27 @@ Lets complete the code and create a linked list. Connect all the code. -if __name__ == '__main__': - llist = LinkedList() - - # Insert words at the beginning - llist.insertAtBeginning(4) # <4> - llist.insertAtBeginning(3) # <3> 4 - llist.insertAtBeginning(2) # <2> 3 4 - llist.insertAtBeginning(1) # <1> 2 3 4 - - # Insert a word at the end - llist.insertAtEnd(10) # 1 2 3 4 <10> - llist.insertAtEnd(7) # 1 2 3 4 10 <7> - - #Insert at a random position - llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7 - # Print the list - llist.printList() + if __name__ == '__main__': + llist = LinkedList() + + # Insert words at the beginning + llist.insertAtBeginning(4) # <4> + llist.insertAtBeginning(3) # <3> 4 + llist.insertAtBeginning(2) # <2> 3 4 + llist.insertAtBeginning(1) # <1> 2 3 4 + + # Insert a word at the end + llist.insertAtEnd(10) # 1 2 3 4 <10> + llist.insertAtEnd(7) # 1 2 3 4 10 <7> + + #Insert at a random position + llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7 + # Print the list + llist.printList() - - output: - 1 2 3 9 4 10 7 +## output: +1 2 3 9 4 10 7 ### Deleting a node from the beginning of a linked list From 4a0576633fc3e06900b2c34e134c0ac5a77de8d1 Mon Sep 17 00:00:00 2001 From: Vinay Sagar <64737008+vinay-sagar123@users.noreply.github.com> Date: Sun, 26 May 2024 14:14:13 +0530 Subject: [PATCH 05/18] Update Linked-list.md change2 --- contrib/ds-algorithms/Linked-list.md | 62 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index a660b1c..e3abc9a 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -25,10 +25,10 @@ Let's code something The smallest Unit: Node -class Node: - def __init__(self, data): - self.data = data # Assigns the given data to the node - self.next = None # Initialize the next attribute to null + class Node: + def __init__(self, data): + self.data = data # Assigns the given data to the node + self.next = None # Initialize the next attribute to null Now, we will see the types of linked list. @@ -45,9 +45,9 @@ Simply think it is a chain of nodes in which each node remember(contains) the ad ### Creating a linked list class -class LinkedList: - def __init__(self): - self.head = None # Initialize head as None + class LinkedList: + def __init__(self): + self.head = None # Initialize head as None ### Inserting a new node at the beginning of a linked list @@ -130,37 +130,37 @@ Connect all the code. ### Deleting a node from the beginning of a linked list check the list is empty otherwise shift the head to next node. -def deleteFromBeginning(self): - if self.head is None: - return "The list is empty" # If the list is empty, return this string - self.head = self.head.next # Otherwise, remove the head by making the next node the new head + def deleteFromBeginning(self): + if self.head is None: + return "The list is empty" # If the list is empty, return this string + self.head = self.head.next # Otherwise, remove the head by making the next node the new head ### Deleting a node from the end of a linked list -def deleteFromEnd(self): - if self.head is None: - return "The list is empty" - if self.head.next is None: - self.head = None # If there's only one node, remove the head by making it None - return - temp = self.head - while temp.next.next: # Otherwise, go to the second-last node - temp = temp.next - temp.next = None # Remove the last node by setting the next pointer of the second-last node to None + def deleteFromEnd(self): + if self.head is None: + return "The list is empty" + if self.head.next is None: + self.head = None # If there's only one node, remove the head by making it None + return + temp = self.head + while temp.next.next: # Otherwise, go to the second-last node + temp = temp.next + temp.next = None # Remove the last node by setting the next pointer of the second-last node to None ### Search in a linked list -def search(self, value): - current = self.head # Start with the head of the list - position = 0 # Counter to keep track of the position - while current: # Traverse the list - if current.data == value: # Compare the list's data to the search value - return f"Value '{value}' found at position {position}" # Print the value if a match is found - current = current.next - position += 1 - return f"Value '{value}' not found in the list" - + def search(self, value): + current = self.head # Start with the head of the list + position = 0 # Counter to keep track of the position + while current: # Traverse the list + if current.data == value: # Compare the list's data to the search value + return f"Value '{value}' found at position {position}" # Print the value if a match is found + current = current.next + position += 1 + return f"Value '{value}' not found in the list" + From b2264d4e6fe3dfe738bc321fe3e6edd946fb9f7e Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:22:13 +0530 Subject: [PATCH 06/18] COMM3 --- contrib/ds-algorithms/Linked-list.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index e3abc9a..147527b 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -25,10 +25,12 @@ Let's code something The smallest Unit: Node + ```python class Node: def __init__(self, data): self.data = data # Assigns the given data to the node self.next = None # Initialize the next attribute to null + ``` Now, we will see the types of linked list. @@ -44,20 +46,24 @@ There are mainly four types of linked list, Simply think it is a chain of nodes in which each node remember(contains) the addresses of it next node. ### Creating a linked list class - + ```python class LinkedList: def __init__(self): self.head = None # Initialize head as None + ``` ### Inserting a new node at the beginning of a linked list + ```python def insertAtBeginning(self, new_data): new_node = Node(new_data) # Create a new node new_node.next = self.head # Next for new node becomes the current head self.head = new_node # Head now points to the new node + ``` ### Inserting a new node at the end of a linked list +```python def insertAtEnd(self, new_data): new_node = Node(new_data) # Create a new node if self.head is None: @@ -67,9 +73,10 @@ Simply think it is a chain of nodes in which each node remember(contains) the ad while last.next: # Otherwise, traverse the list to find the last node last = last.next last.next = new_node # Make the new node the next node of the last node - +``` ### Inserting a new node at the middle of a linked list +```python def insertAtPosition(self, data, position): new_node = Node(data) if position <= 0: #check if position is valid or not @@ -89,21 +96,23 @@ Simply think it is a chain of nodes in which each node remember(contains) the ad return new_node.next = current_node.next #connect the intermediate node current_node.next = new_node - +``` ### Printing the Linked list +```python def printList(self): temp = self.head # Start from the head of the list while temp: print(temp.data,end=' ') # Print the data in the current node temp = temp.next # Move to the next node print() # Ensures the output is followed by a new line - +``` Lets complete the code and create a linked list. Connect all the code. +```python if __name__ == '__main__': llist = LinkedList() @@ -121,7 +130,7 @@ Connect all the code. llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7 # Print the list llist.printList() - +``` ## output: 1 2 3 9 4 10 7 @@ -129,14 +138,15 @@ Connect all the code. ### Deleting a node from the beginning of a linked list check the list is empty otherwise shift the head to next node. - +```python def deleteFromBeginning(self): if self.head is None: return "The list is empty" # If the list is empty, return this string self.head = self.head.next # Otherwise, remove the head by making the next node the new head - +``` ### Deleting a node from the end of a linked list +```python def deleteFromEnd(self): if self.head is None: return "The list is empty" @@ -147,6 +157,7 @@ check the list is empty otherwise shift the head to next node. while temp.next.next: # Otherwise, go to the second-last node temp = temp.next temp.next = None # Remove the last node by setting the next pointer of the second-last node to None + ``` ### Search in a linked list From a1dd770b20179f859dc669fdda163bc7c01a96a2 Mon Sep 17 00:00:00 2001 From: Vinay Sagar <64737008+vinay-sagar123@users.noreply.github.com> Date: Sun, 26 May 2024 14:24:19 +0530 Subject: [PATCH 07/18] Update Linked-list.md chnage3 --- contrib/ds-algorithms/Linked-list.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 147527b..541410c 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -25,12 +25,12 @@ Let's code something The smallest Unit: Node - ```python +```python class Node: def __init__(self, data): self.data = data # Assigns the given data to the node self.next = None # Initialize the next attribute to null - ``` +``` Now, we will see the types of linked list. @@ -46,20 +46,20 @@ There are mainly four types of linked list, Simply think it is a chain of nodes in which each node remember(contains) the addresses of it next node. ### Creating a linked list class - ```python +```python class LinkedList: def __init__(self): self.head = None # Initialize head as None - ``` +``` ### Inserting a new node at the beginning of a linked list - ```python +```python def insertAtBeginning(self, new_data): new_node = Node(new_data) # Create a new node new_node.next = self.head # Next for new node becomes the current head self.head = new_node # Head now points to the new node - ``` +``` ### Inserting a new node at the end of a linked list From beba33d28736209440c9d9cb4784426a9d38ce9b Mon Sep 17 00:00:00 2001 From: Vinay Sagar <64737008+vinay-sagar123@users.noreply.github.com> Date: Sun, 26 May 2024 14:24:51 +0530 Subject: [PATCH 08/18] Update Linked-list.md change4 --- contrib/ds-algorithms/Linked-list.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 541410c..9e51ab5 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -171,21 +171,3 @@ check the list is empty otherwise shift the head to next node. current = current.next position += 1 return f"Value '{value}' not found in the list" - - - - - - - - - - - - - - - - - - From c3b01f340fc1948f8d6f03d4115d822bb07221f7 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:32:08 +0530 Subject: [PATCH 09/18] commit4 --- contrib/ds-algorithms/Linked-list.md | 47 ++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 147527b..194cd92 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -157,11 +157,11 @@ check the list is empty otherwise shift the head to next node. while temp.next.next: # Otherwise, go to the second-last node temp = temp.next temp.next = None # Remove the last node by setting the next pointer of the second-last node to None - ``` +``` ### Search in a linked list - +```python def search(self, value): current = self.head # Start with the head of the list position = 0 # Counter to keep track of the position @@ -171,14 +171,43 @@ check the list is empty otherwise shift the head to next node. current = current.next position += 1 return f"Value '{value}' not found in the list" +``` + +```python + if __name__ == '__main__': + llist = LinkedList() + + # Insert words at the beginning + llist.insertAtBeginning(4) # <4> + llist.insertAtBeginning(3) # <3> 4 + llist.insertAtBeginning(2) # <2> 3 4 + llist.insertAtBeginning(1) # <1> 2 3 4 - - - - - - - + # Insert a word at the end + llist.insertAtEnd(10) # 1 2 3 4 <10> + llist.insertAtEnd(7) # 1 2 3 4 10 <7> + + #Insert at a random position + llist.insertAtPosition(9,4) # 1 2 3 <9> 4 10 7 + llist.insertAtPositon(56,4) # 1 2 3 <56> 9 4 10 7 + + #delete at the beginning + llist.deleteFromBeginning() # 2 3 56 9 4 10 7 + + #delete at the end + llist.deleteFromEnd() # 2 3 56 9 4 10 + # Print the list + llist.printList() +``` + + + +## Real Life uses of Linked List +Music Player – Songs in the music player are linked to the previous and next songs. So you can play songs either from starting or ending of the list. +GPS navigation systems- Linked lists can be used to store and manage a list of locations and routes, allowing users to easily navigate to their desired destination. +Task Scheduling- Operating systems use linked lists to manage task scheduling, where each process waiting to be executed is represented as a node in the list. +Speech Recognition- Speech recognition software uses linked lists to represent the possible phonetic pronunciations of a word, where each possible pronunciation is represented as a node in the list. +and more.... From c91b657e2c186a509cd0e32a3cf398d30c79ab6b Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:36:28 +0530 Subject: [PATCH 10/18] hello --- contrib/ds-algorithms/Linked-list.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 5febd22..0ec285d 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -171,7 +171,6 @@ check the list is empty otherwise shift the head to next node. current = current.next position += 1 return f"Value '{value}' not found in the list" -<<<<<<< HEAD ``` ```python @@ -219,5 +218,3 @@ and more.... -======= ->>>>>>> beba33d28736209440c9d9cb4784426a9d38ce9b From 297d68fadbc26f0f752c3272c9bc04094882b7fe Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:38:31 +0530 Subject: [PATCH 11/18] comm6 --- contrib/ds-algorithms/Linked-list.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 0ec285d..007674f 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -204,9 +204,13 @@ check the list is empty otherwise shift the head to next node. ## Real Life uses of Linked List Music Player – Songs in the music player are linked to the previous and next songs. So you can play songs either from starting or ending of the list. +
GPS navigation systems- Linked lists can be used to store and manage a list of locations and routes, allowing users to easily navigate to their desired destination. +
Task Scheduling- Operating systems use linked lists to manage task scheduling, where each process waiting to be executed is represented as a node in the list. +
Speech Recognition- Speech recognition software uses linked lists to represent the possible phonetic pronunciations of a word, where each possible pronunciation is represented as a node in the list. +
and more.... From e8a1d62febf2195d49d0207f76cd82591fa24c31 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:40:43 +0530 Subject: [PATCH 12/18] commit7 --- contrib/ds-algorithms/Linked-list.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 007674f..95350fd 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -199,17 +199,19 @@ check the list is empty otherwise shift the head to next node. # Print the list llist.printList() ``` +##Output +2 3 56 9 4 10 ## Real Life uses of Linked List -Music Player – Songs in the music player are linked to the previous and next songs. So you can play songs either from starting or ending of the list. +1. Music Player – Songs in the music player are linked to the previous and next songs. So you can play songs either from starting or ending of the list.
-GPS navigation systems- Linked lists can be used to store and manage a list of locations and routes, allowing users to easily navigate to their desired destination. +2. GPS navigation systems- Linked lists can be used to store and manage a list of locations and routes, allowing users to easily navigate to their desired destination.
-Task Scheduling- Operating systems use linked lists to manage task scheduling, where each process waiting to be executed is represented as a node in the list. +3. Task Scheduling- Operating systems use linked lists to manage task scheduling, where each process waiting to be executed is represented as a node in the list.
-Speech Recognition- Speech recognition software uses linked lists to represent the possible phonetic pronunciations of a word, where each possible pronunciation is represented as a node in the list. +4. Speech Recognition- Speech recognition software uses linked lists to represent the possible phonetic pronunciations of a word, where each possible pronunciation is represented as a node in the list.
and more.... From 7e979edff8636325b197246275db488e13952347 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:41:38 +0530 Subject: [PATCH 13/18] commit8 --- contrib/ds-algorithms/Linked-list.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 95350fd..424a8fb 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -199,7 +199,8 @@ check the list is empty otherwise shift the head to next node. # Print the list llist.printList() ``` -##Output +## Output: + 2 3 56 9 4 10 From 4c51b5916e64e1e6f64fa2987905e9e98d9a0efd Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:42:37 +0530 Subject: [PATCH 14/18] c10 --- contrib/ds-algorithms/Linked-list.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 424a8fb..1c4511e 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -207,13 +207,9 @@ check the list is empty otherwise shift the head to next node. ## Real Life uses of Linked List 1. Music Player – Songs in the music player are linked to the previous and next songs. So you can play songs either from starting or ending of the list. -
2. GPS navigation systems- Linked lists can be used to store and manage a list of locations and routes, allowing users to easily navigate to their desired destination. -
3. Task Scheduling- Operating systems use linked lists to manage task scheduling, where each process waiting to be executed is represented as a node in the list. -
4. Speech Recognition- Speech recognition software uses linked lists to represent the possible phonetic pronunciations of a word, where each possible pronunciation is represented as a node in the list. -
and more.... From 45e8763b5a25403f8a3eba79cf0e8a7c0fa46879 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sun, 26 May 2024 14:53:04 +0530 Subject: [PATCH 15/18] com11 --- contrib/ds-algorithms/Linked-list.md | 31 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 1c4511e..11f4016 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -2,7 +2,8 @@ Link list is a linear data Structure which can be defined as collection of objects called nodes that are randomly stored in the memory. A node contains two types of metadata i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory. -The last node of the list contains pointer to the null. + +The last element in a linked list features a null pointer. ## Why use linked list over array? @@ -11,15 +12,15 @@ However, there are some advantage and disadvantage of array which should be know limitations -1. The size of array must be known in advance before using it in the program. -2. Increasing size of the array is a time taking process. It is almost impossible to expand the size of the array at run time. -3. All the elements in the array need to be contiguously stored in the memory. Inserting any element in the array needs shifting of all its predecessors. +1. Before an array can be utilized in a program, its size must be established in advance. +2. Expanding an array's size is a lengthy process and is almost impossible to achieve during runtime. +3. Array elements must be stored in contiguous memory locations. To insert an element, all subsequent elements must be shifted So we introduce a new data structure to overcome these limitations. Linked list is used because, -1. It allocates the memory dynamically. All the nodes of linked list are non-contiguously stored in the memory and linked together with the help of pointers. -2. Sizing is no longer a problem since we do not need to define its size at the time of declaration. List grows as per the program's demand and limited to the available memory space. +1. Dynamic Memory Management: Linked lists allocate memory dynamically, meaning nodes can be located anywhere in memory and are connected through pointers, rather than being stored contiguously. +2. Adaptive Sizing: There is no need to predefine the size of a linked list. It can expand or contract during runtime, adapting to the program's requirements within the constraints of the available memory. Let's code something @@ -206,11 +207,19 @@ check the list is empty otherwise shift the head to next node. ## Real Life uses of Linked List -1. Music Player – Songs in the music player are linked to the previous and next songs. So you can play songs either from starting or ending of the list. -2. GPS navigation systems- Linked lists can be used to store and manage a list of locations and routes, allowing users to easily navigate to their desired destination. -3. Task Scheduling- Operating systems use linked lists to manage task scheduling, where each process waiting to be executed is represented as a node in the list. -4. Speech Recognition- Speech recognition software uses linked lists to represent the possible phonetic pronunciations of a word, where each possible pronunciation is represented as a node in the list. -and more.... + + +Here are a few practical applications of linked lists in various fields: + +1. **Music Player**: In a music player, songs are often linked to the previous and next tracks. This allows for seamless navigation between songs, enabling you to play tracks either from the beginning or the end of the playlist. This is akin to a doubly linked list where each song node points to both the previous and the next song, enhancing the flexibility of song selection. + +2. **GPS Navigation Systems**: Linked lists can be highly effective for managing lists of locations and routes in GPS navigation systems. Each location or waypoint can be represented as a node, making it easy to add or remove destinations and to navigate smoothly from one location to another. This is similar to how you might plan a road trip, plotting stops along the way in a flexible, dynamic manner. + +3. **Task Scheduling**: Operating systems utilize linked lists to manage task scheduling. Each process waiting to be executed is represented as a node in a linked list. This organization allows the system to efficiently keep track of which processes need to be run, enabling fair and systematic scheduling of tasks. Think of it like a to-do list where each task is a node, and the system executes tasks in a structured order. + +4. **Speech Recognition**: Speech recognition software uses linked lists to represent possible phonetic pronunciations of words. Each potential pronunciation is a node, allowing the software to dynamically explore different pronunciation paths as it processes spoken input. This method helps in accurately recognizing and understanding speech by considering multiple possibilities in a flexible manner, much like evaluating various potential meanings in a conversation. + +These examples illustrate how linked lists provide a flexible, dynamic data structure that can be adapted to a wide range of practical applications, making them a valuable tool in both software development and real-world problem-solving. From 1c6166e03c00415a836f784659b9016f91695dc3 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Mon, 27 May 2024 08:38:32 +0530 Subject: [PATCH 16/18] Rename Linked-list.md to linked-list.md --- contrib/ds-algorithms/{Linked-list.md => linked-list.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/ds-algorithms/{Linked-list.md => linked-list.md} (100%) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/linked-list.md similarity index 100% rename from contrib/ds-algorithms/Linked-list.md rename to contrib/ds-algorithms/linked-list.md From fd0c10df6bb1e5c3d11e42861db95dc212aa9777 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Mon, 27 May 2024 08:39:03 +0530 Subject: [PATCH 17/18] Update linked-list.md --- contrib/ds-algorithms/linked-list.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/contrib/ds-algorithms/linked-list.md b/contrib/ds-algorithms/linked-list.md index 11f4016..ddbc6d5 100644 --- a/contrib/ds-algorithms/linked-list.md +++ b/contrib/ds-algorithms/linked-list.md @@ -220,13 +220,3 @@ Here are a few practical applications of linked lists in various fields: 4. **Speech Recognition**: Speech recognition software uses linked lists to represent possible phonetic pronunciations of words. Each potential pronunciation is a node, allowing the software to dynamically explore different pronunciation paths as it processes spoken input. This method helps in accurately recognizing and understanding speech by considering multiple possibilities in a flexible manner, much like evaluating various potential meanings in a conversation. These examples illustrate how linked lists provide a flexible, dynamic data structure that can be adapted to a wide range of practical applications, making them a valuable tool in both software development and real-world problem-solving. - - - - - - - - - - From 76df5a6a9fb679418444caed6e233c456f19991d Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Mon, 27 May 2024 08:39:22 +0530 Subject: [PATCH 18/18] Update index.md --- contrib/ds-algorithms/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/ds-algorithms/index.md b/contrib/ds-algorithms/index.md index 4b6e20d..c61ca0b 100644 --- a/contrib/ds-algorithms/index.md +++ b/contrib/ds-algorithms/index.md @@ -8,4 +8,4 @@ - [Searching Algorithms](searching-algorithms.md) - [Greedy Algorithms](greedy-algorithms.md) - [Dynamic Programming](dynamic-programming.md) -- [Linked list](Linked-list.md) +- [Linked list](linked-list.md)