0% found this document useful (0 votes)
13 views4 pages

Assignment LL Foronda

The document explains linked lists, a linear data structure where elements are stored in nodes linked by pointers. It describes the differences between singly linked lists, which allow one-way traversal, and doubly linked lists, which enable two-way traversal. Additionally, it outlines key operations on linked lists, including traversal, insertion, deletion, searching, updating, sorting, and merging.

Uploaded by

deltavintage0926
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Assignment LL Foronda

The document explains linked lists, a linear data structure where elements are stored in nodes linked by pointers. It describes the differences between singly linked lists, which allow one-way traversal, and doubly linked lists, which enable two-way traversal. Additionally, it outlines key operations on linked lists, including traversal, insertion, deletion, searching, updating, sorting, and merging.

Uploaded by

deltavintage0926
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Foronda, John Dave D.

BSCS – 2A
Assignment
1. What is Linked List?
A linked list is a type of linear data structure in which the members (elements) are not
stored in consecutive memory regions. Whereas a linked list consists of nodes which
contains a data field and a reference(link) to the next node in the list. A linked list's
elements are linked via pointers, just as showed in the diagram below:

data next data next data next

HEAD NULL

2. How the types of LL differ from one another?


Singly Linked List is a type of data structure in which each node contains data and
reference(link) to the next node although this allows for efficient insertion and
removal of elements this linked list is still a one-way traversal. Which means that
navigation is done only in one way from where the direction goes, from the first node
to the last node.

While, Doubly Linked List is a type of data structure that also contains data and
reference(link) to the next node but it can go to the previous node in the sequence.
Unlike the Singly Linked List, this allows a two-way traversal which means that
navigation is made easier because it can traverse the list in both directions not only in
the front.

3. Illustrate a singly LL

start

data next data next data null

4. Illustrate a doubly LL

start

prev data next prev data next prev data null

null
5. Enumerate & describe the operations in LL
o Traversal: to traverse all the nodes one after another.
o Example:
void traverseLL(Node head) {
while(head != NULL)
{
print(head.data)
head = head.next
}
}

o Insertion: to add a node at the given position.


o Example:
Node insertAtBegin(Node head, int val)
{
newNode = new Node(val)
if(head == NULL)
return newNode
else
{
newNode.next = head
return newNode
}
}

o Deletion: to delete a node.


o Example:
Node deleteLL(Node head, Node del)
{
if(head == del)
{
return head.next
}
Node temp = head

while( temp.next != NULL )


{
if(temp.next == del)
{
temp.next = temp.next.next
delete del
return head
}
temp = temp.next
}
return head
}

o Searching: to search an element(s) by value.


o Example:
bool searchLL(Node head, int val)
{
Node temp = head
while( temp != NULL)
{
if( temp.data == val )
return true
temp = temp.next
}
return false
}

o Updating: to update a node.


o Example:
void updateLL(Node head, int val, int newVal)
{
Node temp = head
while(temp != NULL)
{
if( temp.data == val)
{
temp.data = newVal
return
}
temp = temp.next
}
}

o Sorting: to arrange nodes in a linked list in a specific order.


o Merging: to merge two linked lists into one.
Reference

Hatim. (2023). What is the difference between a singly and a doubly linked list? TutorChase.

https://www.tutorchase.com/answers/a-level/computer-science/what-is-the-difference-

between-a-singly-and-a-doubly-linked-list (Question 2)

Linked list data structure. (2015, December 11). GeeksforGeeks.

https://www.geeksforgeeks.org/data-structures/linked-list/ (Question 1)

S, R. A. (2021, May 17). Linked list in a data structure: All you need to know | Simplilearn.

Simplilearn.com. https://www.simplilearn.com/tutorials/data-structure-tutorial/linked-

list-in-data-structure (Questions 3 and 4)

Types of linked list and operation on linked list. (n.d.). AfterAcademy | Platform for learning

coding & software development. https://afteracademy.com/blog/types-of-linked-list-

and-operation-on-linked-list/ (Question 5)

You might also like