You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contrib/ds-algorithms/Linked-list.md
+20-11Lines changed: 20 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,8 @@
2
2
3
3
Link list is a linear data Structure which can be defined as collection of objects called nodes that are randomly stored in the memory.
4
4
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.
5
-
The last node of the list contains pointer to the null.
5
+
6
+
The last element in a linked list features a null pointer.
6
7
7
8
## Why use linked list over array?
8
9
@@ -11,15 +12,15 @@ However, there are some advantage and disadvantage of array which should be know
11
12
12
13
limitations
13
14
14
-
1.The size of array must be known in advance before using it in the program.
15
-
2.Increasing size of the arrayis a time taking process. It is almost impossible to expand the size of the array at run time.
16
-
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.
15
+
1.Before an array can be utilized in a program, its size must be established in advance.
16
+
2.Expanding an array's size is a lengthy process and is almost impossible to achieve during runtime.
17
+
3.Array elements must be stored in contiguous memory locations. To insert an element, all subsequent elements must be shifted
17
18
18
19
So we introduce a new data structure to overcome these limitations.
19
20
20
21
Linked list is used because,
21
-
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.
22
-
2. Sizingis 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.
22
+
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.
23
+
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.
23
24
24
25
Let's code something
25
26
@@ -206,11 +207,19 @@ check the list is empty otherwise shift the head to next node.
206
207
207
208
208
209
## Real Life uses of Linked List
209
-
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.
210
-
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.
211
-
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.
212
-
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.
213
-
and more....
210
+
211
+
212
+
Here are a few practical applications of linked lists in various fields:
213
+
214
+
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.
215
+
216
+
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.
217
+
218
+
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.
219
+
220
+
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.
221
+
222
+
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.
0 commit comments