Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary linked list

Rating
-
Sold
-
Pages
23
Uploaded on
27-05-2023
Written in
2022/2023

In these comprehensive notes on data structures in C, you will gain a deep understanding of the fundamental concepts and practical implementation techniques. Whether you're a beginner or an experienced programmer, these notes will equip you with the knowledge and skills to design and manipulate data structures effectively. Explore topics such as arrays, linked lists, stacks, queues, trees, graphs, and more, as you discover how to optimize memory usage and enhance program efficiency. With clear explanations, examples, and code snippets, these notes will empower you to build efficient solutions and elevate your proficiency in data structure manipulation using the C programming language.

Show more Read less
Institution
Course

Content preview

LINKED LIST
A linked list is a linear data structure, in which the elements are not
stored at contiguous memory locations. The elements in a linked list are
linked using pointers as shown in the below figure:




In simple words, a linked list consists of nodes where each node contains
a data field and a link(reference) to the next node in the list.
Like arrays, Linked List is a linear data structure. Unlike arrays, linked
list elements are not stored at a contiguous location.


1. CONCEPT OF LINKED LIST
1. Each node in a linked list consists of two parts: the data/value being
stored and a reference/link to the next node.
2. The last node in the list points to null to indicate the end of the list.
3. Unlike arrays, linked lists don't require consecutive memory
locations. Nodes can be scattered throughout memory.
4. This flexibility allows dynamic resizing and efficient insertion and
deletion operations at any position in the list.
5. Linked lists are useful when frequent modifications to the data
structure are expected, like inserting or removing elements.
6. However, accessing elements in a linked list sequentially is slower
compared to arrays because you need to follow the references from
node to node.
7. There are different types of linked lists: singly linked lists (with
references to the next node only), doubly linked lists (with references
to both the previous and next nodes), and circular linked lists (where
the last node points back to the first node).
8. Singly linked lists are the simplest form and require less memory per
node, while doubly linked lists allow for more efficient traversal in both
directions.
9. Circular linked lists are useful in scenarios where cyclic operations or
circular data representation are needed.
10. Overall, linked lists provide flexibility and efficiency for organizing
and managing data in a linear structure, especially when frequent
insertions, deletions, or dynamic resizing are required.
2. MEMORY REPRESENTATION

,1. Each node in a linked list is dynamically allocated its own memory
space.
2. A node contains two components: the data/value being stored and a
reference (or link) to the next node.
3. The memory for each node includes space for the data and the
reference.
4. Nodes are linked together by storing the memory address of the next
node in the current node's reference.
5. The last node in the list typically has a reference that points to null
to indicate the end of the list.
6. The memory allocation for nodes in a linked list is dynamic, allowing
for efficient resizing and modification.
7. Each node can have a different size in memory, depending on the size
of the data and the size of the reference.
8. The dynamic memory allocation allows for efficient insertion and
deletion operations in a linked list.
9. The memory representation of a linked list reflects the sequential
connection of nodes, forming the linear structure.
10. Overall, linked lists offer flexibility in memory allocation, enabling
efficient management of data in a dynamic structure.
3. SINGLE LINKED LIST
A singly linked list is a type of linked list where each node contains a
data element and a reference (link) to the next node in the sequence. In
a singly linked list, traversal is possible only in one direction, from the
head (the first node) to the tail (the last node).


Here are some key points about singly linked lists:


1. Node Structure: Each node in a singly linked list consists of two
components:
- Data: The value or payload stored in the node.
- Next: A reference (pointer) to the next node in the list.


2. Head and Tail: The head points to the first node, and the tail points
to the last node in the list. The tail node's next reference is typically set
to NULL to indicate the end of the list.


3. Traversal: To traverse a singly linked list, we start at the head and
follow the next references until we reach the tail. This allows sequential
access to the elements.

, 4. Insertion and Deletion: Inserting or deleting a node in a singly linked
list involves adjusting the next references of the affected nodes.
Insertion can be done at the beginning (prepend), at the end (append),
or at any position in the middle. Deletion involves updating the next
reference of the preceding node to bypass the deleted node.


5. Dynamic Size: Singly linked lists can grow and shrink dynamically as
nodes are added or removed. This makes them suitable for scenarios
where the size of the list may change frequently.


Singly linked lists are commonly used when efficient insertion and
deletion operations are required, but random access to elements is not
a primary concern. They are used in various applications, such as
implementing stacks, queues, and as building blocks for more complex
data structures.
4. TRAVERSAL
Traversing a singly linked list means visiting each node in the list to
access or perform some operation on its data.
Displaying the contents of a linked list is known as traversing a linked
list. It is very simple.
The algorithm for traversing a list
• Start with the head of the list. Access the content of the head
node if it is not null.
• Then go to the next node(if exists) and access the node
information
• Continue until no more nodes (that is, you have reached the null
node)
The following section of a code shows how to traverse a linked list.
struct node *ptr = head;
printf("\n\nList elements are - \n");
while(ptr != NULL)
{
printf("%d ",ptr->data);
ptr = ptr->next;
}
We keep moving the ptr node to the next one and display its contents.
When ptr is NULL, we know that we have reached the end of the linked
list so we get out of the while loop.

Written for

Course

Document information

Uploaded on
May 27, 2023
Number of pages
23
Written in
2022/2023
Type
SUMMARY

Subjects

$13.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
anjithaav

Get to know the seller

Seller avatar
anjithaav university institute of technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
14
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions