Skip to content

Commit

Permalink
Merge pull request #1572 from jainaryan04/main
Browse files Browse the repository at this point in the history
Create a-very-useful-data-structure-linked-lists.md
  • Loading branch information
ajay-dhangar authored Nov 5, 2024
2 parents da6a4de + 4642ef5 commit c119a51
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 43 deletions.
86 changes: 43 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,26 @@ Thanks to these amazing people who have contributed to the **Algo** project:
</a>
</td>
<td align="center">
<a href="https://github.com/Shariq2003">
<img src="https://avatars.githubusercontent.com/u/109452033?v=4" width="100;" alt="Shariq2003"/>
<a href="https://github.com/PrAyAg9">
<img src="https://avatars.githubusercontent.com/u/114804510?v=4" width="100;" alt="PrAyAg9"/>
<br />
<sub><b>Shariq</b></sub>
<sub><b>Prayag Thakur</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/MithanshuHedau">
<img src="https://avatars.githubusercontent.com/u/144697427?v=4" width="100;" alt="MithanshuHedau"/>
<a href="https://github.com/Shariq2003">
<img src="https://avatars.githubusercontent.com/u/109452033?v=4" width="100;" alt="Shariq2003"/>
<br />
<sub><b>Mithanshu Hedau</b></sub>
<sub><b>Shariq</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Mahateaa">
<img src="https://avatars.githubusercontent.com/u/160406913?v=4" width="100;" alt="Mahateaa"/>
<a href="https://github.com/MithanshuHedau">
<img src="https://avatars.githubusercontent.com/u/144697427?v=4" width="100;" alt="MithanshuHedau"/>
<br />
<sub><b>Mahathi</b></sub>
<sub><b>Mithanshu Hedau</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -363,10 +363,10 @@ Thanks to these amazing people who have contributed to the **Algo** project:
</a>
</td>
<td align="center">
<a href="https://github.com/PrAyAg9">
<img src="https://avatars.githubusercontent.com/u/114804510?v=4" width="100;" alt="PrAyAg9"/>
<a href="https://github.com/Mahateaa">
<img src="https://avatars.githubusercontent.com/u/160406913?v=4" width="100;" alt="Mahateaa"/>
<br />
<sub><b>Prayag Thakur</b></sub>
<sub><b>Mahathi</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -393,17 +393,17 @@ Thanks to these amazing people who have contributed to the **Algo** project:
</a>
</td>
<td align="center">
<a href="https://github.com/Subashree-selvaraj">
<img src="https://avatars.githubusercontent.com/u/132484553?v=4" width="100;" alt="Subashree-selvaraj"/>
<a href="https://github.com/Abhishek2634">
<img src="https://avatars.githubusercontent.com/u/136872441?v=4" width="100;" alt="Abhishek2634"/>
<br />
<sub><b>subashree</b></sub>
<sub><b>Abhishek Farshwal</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Abhishek2634">
<img src="https://avatars.githubusercontent.com/u/136872441?v=4" width="100;" alt="Abhishek2634"/>
<a href="https://github.com/Subashree-selvaraj">
<img src="https://avatars.githubusercontent.com/u/132484553?v=4" width="100;" alt="Subashree-selvaraj"/>
<br />
<sub><b>Abhishek Farshwal</b></sub>
<sub><b>subashree</b></sub>
</a>
</td>
<td align="center">
Expand Down Expand Up @@ -457,27 +457,34 @@ Thanks to these amazing people who have contributed to the **Algo** project:
<sub><b>riddhi</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Mansi07sharma">
<img src="https://avatars.githubusercontent.com/u/142892607?v=4" width="100;" alt="Mansi07sharma"/>
<br />
<sub><b>Mansi07sharma</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/PavanTeja2005">
<img src="https://avatars.githubusercontent.com/u/98730339?v=4" width="100;" alt="PavanTeja2005"/>
<br />
<sub><b>PavanTeja2005</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/mehul-m-prajapati">
<img src="https://avatars.githubusercontent.com/u/7879392?v=4" width="100;" alt="mehul-m-prajapati"/>
<br />
<sub><b>Mehul Prajapati</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/Mansi07sharma">
<img src="https://avatars.githubusercontent.com/u/142892607?v=4" width="100;" alt="Mansi07sharma"/>
<a href="https://github.com/jainaryan04">
<img src="https://avatars.githubusercontent.com/u/138214350?v=4" width="100;" alt="jainaryan04"/>
<br />
<sub><b>Mansi07sharma</b></sub>
<sub><b>Aryan Ramesh Jain</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -487,13 +494,6 @@ Thanks to these amazing people who have contributed to the **Algo** project:
<sub><b>sarthaxtic</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/shimmer12">
<img src="https://avatars.githubusercontent.com/u/92056170?v=4" width="100;" alt="shimmer12"/>
<br />
<sub><b>Srishti Soni</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Asmi1108">
<img src="https://avatars.githubusercontent.com/u/174241668?v=4" width="100;" alt="Asmi1108"/>
Expand All @@ -502,10 +502,10 @@ Thanks to these amazing people who have contributed to the **Algo** project:
</a>
</td>
<td align="center">
<a href="https://github.com/T-Fathima">
<img src="https://avatars.githubusercontent.com/u/148070120?v=4" width="100;" alt="T-Fathima"/>
<a href="https://github.com/shimmer12">
<img src="https://avatars.githubusercontent.com/u/92056170?v=4" width="100;" alt="shimmer12"/>
<br />
<sub><b>Tatheer Fathima</b></sub>
<sub><b>Srishti Soni</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -524,6 +524,13 @@ Thanks to these amazing people who have contributed to the **Algo** project:
<sub><b>Tejas Athalye</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/T-Fathima">
<img src="https://avatars.githubusercontent.com/u/148070120?v=4" width="100;" alt="T-Fathima"/>
<br />
<sub><b>Tatheer Fathima</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Siddhart2004">
<img src="https://avatars.githubusercontent.com/u/90645484?v=4" width="100;" alt="Siddhart2004"/>
Expand All @@ -538,13 +545,6 @@ Thanks to these amazing people who have contributed to the **Algo** project:
<sub><b>sriraghavi22</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/jvkousthub">
<img src="https://avatars.githubusercontent.com/u/162019723?v=4" width="100;" alt="jvkousthub"/>
<br />
<sub><b>Kousthub J V</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/govindumeesala">
<img src="https://avatars.githubusercontent.com/u/129055361?v=4" width="100;" alt="govindumeesala"/>
Expand All @@ -562,10 +562,10 @@ Thanks to these amazing people who have contributed to the **Algo** project:
</tr>
<tr>
<td align="center">
<a href="https://github.com/jainaryan04">
<img src="https://avatars.githubusercontent.com/u/138214350?v=4" width="100;" alt="jainaryan04"/>
<a href="https://github.com/jvkousthub">
<img src="https://avatars.githubusercontent.com/u/162019723?v=4" width="100;" alt="jvkousthub"/>
<br />
<sub><b>Aryan Ramesh Jain</b></sub>
<sub><b>Kousthub J V</b></sub>
</a>
</td>
<td align="center">
Expand Down
98 changes: 98 additions & 0 deletions blog/a-very-useful-data-structure-linked-lists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
slug: a-very-useful-data-structure-linked-lists
title: A Very Useful Data Structure - Linked Lists
authors: [Aryan-Jain]
tags: [linked-list, data-structures, algorithms, C++, java, python]
---

A linked list is a linear data structure where elements are not stored in contiguous memory locations. Instead, each element, or node, contains data and a pointer to the next node in the sequence. This structure offers flexibility and dynamic memory allocation, making it a powerful tool for various programming tasks.

<!-- truncate -->

In this blog, we'll explore:

- **Dynamic Size**: How linked lists can grow or shrink dynamically as needed.
- **Efficiency**: The benefits of insertion and deletion operations.
- **Flexibility**: Representing different data structures.

---

## Why Use Linked Lists?

* **Dynamic Size:** Linked lists can grow or shrink dynamically as needed, unlike arrays which have a fixed size.
* **Efficient Insertion and Deletion:** Inserting or deleting elements in a linked list is efficient, especially when operations are performed at the beginning or end of the list.
* **Flexibility:** Linked lists can represent various data structures, such as stacks, queues, and trees.
* **Memory Efficient:** Linked lists can be more memory efficient than arrays in certain scenarios, as they don't require contiguous memory allocation.

## Types of Linked Lists

1. **Singly Linked List:** Each node points to the next node.
2. **Doubly Linked List:** Each node points to both the next and previous nodes.
3. **Circular Linked List:** The last node points back to the first node, forming a circular structure.

## Common Operations on Linked Lists

* **Traversal:** Iterating through the list to access each node.
* **Insertion:** Adding a new node at a specific position.
* **Deletion:** Removing a node from a specific position.
* **Searching:** Finding a node with a specific value.
* **Reversal:** Reversing the order of nodes in the list.

## Real-world Applications

* Implementing data structures like stacks and queues
* Managing dynamic memory
* Creating undo/redo functionality in software
* Implementing music players and video players
* Implementing hash tables

## C Code Examples

### Singly Linked List

```c
#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};

// Function to create a new node
struct Node* newNode(int data) {
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
new_node->data = data;
new_node->next = NULL;
return new_node;
}

// Function to insert a new node at the beginning
void insertAtBeginning(struct Node** head_ref, int new_data) {
struct Node* new_node = newNode(new_data);
new_node->next = (*head_ref);
(*head_ref) = new_node;
}

// Function to print the linked list
void printList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
printf("\n");
}

int main() {
struct Node* head = NULL;

insertAtBeginning(&head, 3);
insertAtBeginning(&head, 2);
insertAtBeginning(&head, 1);

printList(head);

return 0;
}
```
13 changes: 13 additions & 0 deletions blog/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,16 @@ Harshitha-Grandhi:
socials:
linkedin: https://www.linkedin.com/in/harshitha-grandhi-0a0890308/
github: https://github.com/Grandhi-Harshitha

Aryan-Jain:
name: Aryan Jain
title: B.Tech (CSE) Student
url: https://github.com/jainaryan04
image_url: https://avatars.githubusercontent.com/u/138214350?v=4
email: [email protected]
page: true # Turns the feature on
description: >
full stack developer
socials:
linkedin: https://www.linkedin.com/in/jainaryan04/
github: https://github.com/jainaryan04

0 comments on commit c119a51

Please sign in to comment.