DSA Lab 4
DSA Lab 4
DSA Lab 4
824-FOC/BSIT/F-22
Lab Manual for Data Structures
Lab-4
Compare linear linked list with doubly linked list and provide three differences between
the two structures.
Both linear linked lists and doubly linked lists are fundamental data structures that store
elements in a sequential order. However, they differ in how they link these elements together.
Here's a breakdown of three key differences:
1. Node Structure:
Linear Linked List (Singly Linked List): Each node contains data and a single
reference (pointer) to the next node in the list. It's like a one-way street, you can
only traverse forward.
Doubly Linked List: Each node contains data, a reference to the next node, and a
reference to the previous node. Think of it as a two-way street, allowing for
traversal in both forward and backward directions.
2. Traversal:
Linear Linked List: Due to the single pointer, you can only iterate through the list
from the beginning towards the end.
Doubly Linked List: With pointers to both next and previous nodes, you can
efficiently traverse the list in both directions, starting from any node.
3. Memory Usage:
Linear Linked List: A node requires less memory as it only stores data and a
single pointer.
Doubly Linked List: A node requires more memory as it stores data and two
pointers (one for next and one for previous).
, a singly linked list offers a simpler structure with lower memory usage but limited traversal
options. A doubly linked list provides more flexibility for two-way traversal but comes at the
cost of increased memory usage.
List three real world examples in which doubly linked list structures can be used.
Doubly linked lists find applications in various real-world scenarios due to their flexibility in
traversal and efficient insertion/deletion operations. Here are three examples:
1. Text Editors:
Text editors often use doubly linked lists to implement features like undo and redo
functionality. Each edit operation can be stored as a node in the doubly linked list,
with pointers to both the previous and next edits. This allows users to traverse
backward and forward through the editing history efficiently, enabling undoing or
redoing changes.
2. Browser History:
Web browsers maintain a history of visited web pages, allowing users to navigate
backward and forward through their browsing sessions. Doubly linked lists are
commonly used to implement this history functionality. Each web page visit is stored
as a node in the doubly linked list, enabling efficient traversal both backward (to
previous pages) and forward (to pages revisited after going back).
3. Music Playlist Management:
Music player applications often use doubly linked lists to manage playlists. Each
song in the playlist can be represented as a node in the doubly linked list, with
pointers to the previous and next songs. This enables features like shuffling,
repeating, skipping forward or backward through songs, and dynamically modifying
the playlist (adding, removing, or rearranging songs) efficiently.
In these examples, the use of doubly linked lists allows for efficient navigation, manipulation,
and management of dynamic data collections, which are common requirements in various
software applications.
Practice TASK-1
On the other hand, a doubly linked list is a concrete data structure, i.e. its implementation
would
be same for every programmer. It is a way for storing data.
Following cases should be considered while implementing DECK:
Case 1: Insert at the start of the queue
Case 2: Delete from the start of queue
Case 3: Insert at the end of the queue
Case 4: Delete from the end of queue
Output:
Implement a program using Doubly LinkedList. Your doubly linked list should store
information
of students (Reg_no., Name, CGPA, city, age). Your program should provide following
functionalities:
Insert at Front
Insert at Rear
Insert in middle
Delete from front
Delete from rear
Delete from middle
Display all the data
Output :