0% found this document useful (0 votes)
9 views

Documentation On Linked List in Data Structures and Algorithms 3

data
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Documentation On Linked List in Data Structures and Algorithms 3

data
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Documentation on Linked List in Data Structures and Algorithms (DSA)

LEADER:
ALLEXIA, PAPA D. – PREZI, DOCUMENTATION, CODING

MEMBERS:
FABUL, APRIL JOY G. – LIFE SCENARIO
PAGALAN, MIKECAELLA M. – DOCUMENTATION, OBJECTIVES, CODING
PELAEZ, JHON CEDRICK C. – CONCLUSION, LIFE SCENARIO
PERLAS, CHARLS B. – EXAMPLE, CODING
DE PADUA, JERIC – INTRODUCTION, CODING
INTRODUCTION TO LINKED LIST
Linked list is one of the most important data structures to maintain information.

Each element of a linked list is termed as a "node".

A node holds two elements, namely, data and a reference, or pointer to the next node in the sequence to
form a chain of linked nodes.
In this documentation, we will discuss the structure, operations, and types of linked lists.
Beginning with the basic components of a linked list, including nodes, data, and pointers, we discuss
important operations found in a linked list: insertion, deletion, traversal, and searching.

We will then proceed to discuss the various types of linked lists, like singly linked lists, doubly linked
lists, and circular linked lists.
For better understanding, we'll use examples taken from real-life scenarios of using linked lists:
queue at a ticket booth, video editing, Ferris wheel.
Finally, we will write each of the above-mentioned types of linked list in JavaScript, providing
examples for every one of them. By the end of this document, you will have a good knowledge of how linked
lists are one of the powerful things used in programming.

OBJECTIVES
By the end of this documentation, you will:
 Understand the Structure of Linked Lists: Learn the building blocks of linked lists, including
nodes, data, and pointers.
 Learn Linked List Operations: Master key operations such as insertion, deletion, traversal, and
searching for singly, doubly, and circular linked lists.
 Explore Types of Linked Lists: Understand the three main types: singly, doubly, and circular linked
lists, and learn their unique properties and implementations.
 Understand Practical Applications: Identify the real-life uses of linked lists in task scheduling, web
browsers, music playlist, and other scenarios.
 Implement Linked Lists in JavaScript: Create and manipulate linked lists with JavaScript code
implementations for each type.
WHAT IS A LINKED LIST?

A linked list is an arrangement of nodes, and each of the nodes holds two parts:
 Data: the value actually stored in the node.
 Next Pointer: refers to a reference that points at the next node in the sequence.
A linked list begins with a head pointer that refers to the first node within the list. If the list is empty,
the head refers to the null.

Basic Terminologies in Linked Lists


 Node: It is the basic unit that holds some data and a reference or address to the next node.
 Head: It's the head of the list, i.e., the first node.
 Data: It represents the element or value stored in a node.
 Next Pointer: It is the reference or address which points to the next node in the list.
 Tail: It is the last node in the list, whose next reference is null.
LEARNING LINKED LIST OPERATIONS
To properly apply the linked list data structure, one should know how to perform the most important
operations as follows:

1. Insertion
 At the Beginning: Add a node to the front of the list.
 At the End: Add a node to the end of the list.
 After a Given Node: Add a node after a specific node in the list.
2. Deletion
 From the Beginning: Removing the first node.
 From the End: Removing the last node.
 A Specific Node: Removing a node with a specified value.
3. Traversal in Singly Linked List

Traverse the list and printing each node's data:

 Start with the head node.


 While the current node is not null:
o Print the data of the current node.
o Move to the next node.

4. Searching
Find a node with a given value from the list; this, generally, requires all the traversal from the beginning of
a list until it finds a desired value.
TYPES OF LINKED LISTS
1. Singly Linked List

In a Singly Linked List, each node contains both data and a reference to the next node. Traversal is one
way; from one node to another until the last node whose next pointer is null.

2. Doubly Linked List

A doubly linked list has two pointers in every node: one pointing to the next node and another to the
previous node. It is, therefore, more versatile than a singly linked list because it can be traversed in either
direction.

3. Circular Linked List


It is just a cycle with the last node pointing back to the first node in a Circular Linked List. This kind of
data structure is required in applications that require continuous traversal without the need for a null reference.
Singly Linked List Implementation in JavaScript:
Doubly Linked List Implementation in JavaScript:
Circular Linked List Implementation in JavaScript:
REAL LIFE SCENARIO OF LINKED LIST
First Scenario: Queue of people at a ticket booth
Scenario: People in line at a ticket booth is an example of a singly linked list.
Representation:
 Node: Represents a person in the queue. Contains:
o data (e.g., person's name)

o next (pointer to the next person in the queue)

 Linked List: Represents the entire queue.


Contains:
o head (pointer to the first person in the queue)

o tail (pointer to the last person in the queue)

Operations:
1. Insert at the beginning (enqueue): A new person joins the queue at the front.
2. Insert at the back (enqueue): A new person joins the queue at the back.
3. Insert at a given position: A person joins the queue at a given position (e.g., someone cutting in line).
Example scenarios:
 New customer comes to the ticket counter:
o Add the person to the tail of the linked list (insert at the back).

 Someone cuts in line:


o Insert the person at a given position in the linked list (insert at a given point).

 First person in the queue purchases a ticket:


o Remove the head of the linked list (dequeue).

Second Scenario: Video Editing


Scenario: Video editing is putting together and even manipulating a number of video clips into a final
product.
Representation:
 Video Clip: Node of doubly linked list.
 Data: The video clip has information such as content, duration and more.
 Previous: In the sequence, pointer to the next video clip
 Next: Pointer to the next video clip in the sequence.
 Video Sequence: This constructs a doubly linked list that is a sequence of video clips.
Operations:
1. Insert at the beginning (prepend): Add a new video clip to the start of the sequence. This might be
useful when you want to add an intro or title sequence.
2. Insert at the end (append): Add a new video clip to the end of the sequence. This is common when
adding a closing sequence or credits.
3. Insert at a given point: Insert a new video clip between two existing clips. This is crucial for adding
transitions, effects, or additional footage.
4. Remove a video clip: Delete a specific video clip from the sequence. This might be necessary if you
need to cut out unwanted footage or make changes to the timeline.
5. Reverse the sequence: Reverse the order of the video clips. This can be used to create a different
viewing experience or for special effects.
Example Scenarios:
 Adding a transition effect: Insert a transition video clip between two existing clips.
 Cutting out unwanted footage: Remove a specific video clip from the sequence.
 Reordering clips: Rearrange the order of clips to change the story or pacing.
 Applying a filter to multiple clips: Traverse the doubly linked list, applying the filter to each video
clip.

Third Scenario: The Ferris Wheel


Scenario: Represents the continuous rotation of seats on a Ferris wheel.
Representation:
In the Ferris wheel analogy:
 Node: Each seat on the Ferris wheel represents a node in the linked list.
 Data: The node's data might include the seat number, passenger information, or any other relevant
details.
 Next Pointer: Each seat (node) has a pointer to the next seat (node) in the circular order.
Operations
Common operations on a circular linked list include:
 Insertion: Adding a new seat (node) to the wheel.
 Deletion: Removing a seat (node) from the wheel.
 Traversal: Iterating through the seats (nodes) in a circular fashion.
Example Scenario: Ferris Wheel Ride
1. Initialization: The Ferris wheel starts with a certain number of seats (nodes) connected in a circular
manner.
2. Boarding: As passengers arrive, they are assigned to available seats (nodes).
3. Rotation: The Ferris wheel begins to rotate, simulating traversal through the circular linked list.
4. Disembarking: When passengers reach their destination, they disembark, and their seats (nodes)
become available for new passengers.
IMPLEMENTING LINKED LIST IN JAVASCRIPT
Complete Implementation Example
Here’s a complete JavaScript implementation for a singly linked list with all basic operations:
CONCLUSION
In summary, the linked list is an essential data structure with a flexible way of handling dynamic data,
where each node will contain a data element and a pointer for its next node. With their potential to operate
efficiency within linked lists on operations such as insertion, deletion, and even searching, it becomes more
valuable in scenarios where the dynamic handling of data is relatively important. The three types of linked
lists—singly, doubly, and circular—provide differing amounts of flexibility and directionality suited to
different applications. While the singly linked list allows for one-way traversal, the doubly linked list allows
bidirectional movement, and the circular linked list allows infinite looping, the structures are highly adaptable
to a variety of problem domains.
The actual world applications of linked lists further elaborate the utility of these structures: an example
is that a single link list models a queue at the ticket booth very efficiently, when there is an ongoing resizing
with dynamic and efficient insertions and deletion; a lot of video editing works on doubling linked lists, where
manipulation of video clips can be performed seamlessly through reorder, inserting transitions, or removal of
unwanted footage. Finally, the design of a Ferris wheel would really resemble that of a circular linked list
where traveling through the list in continuous fashion as well as having no particular start or ending point is
quite fundamental.
Ultimately, a set of linked lists presents an extremely efficient, flexible, and space-controllable way of
dealing with data in all sorts of applications. Their dynamic nature allows them to grow or shrink according to
the needs of a process, making them best suited for systems whose data size or structures change. Linked lists
are an invaluable tool in the toolkit of every programmer or system designer-from simple queues to complex
processes like video editing or continuous loops.

You might also like