DS Sem 2 Case Study PDF
DS Sem 2 Case Study PDF
– 10
CASE STUDY
Aim – Identify best suited Data structures for solving real world problem.
Hardware/software required – Turbo C
1. INTRODUCTION
A data structure is a storage that is used to store and organize data. It is a way of arranging data on a
computer so that it can be accessed and updated efficiently.
A data structure is not only used for organizing the data. It is also used for processing, retrieving, and
storing data. There are different basic and advanced types of data structures that are used in almost
every program or software system that has been developed. So we must have good knowledge about
data structures.
Linear data structure: Data structure in which data elements are arranged sequentially or linearly,
where each element is attached to its previous and next adjacent elements, is called a linear data
structure.
Examples of linear data structures are array, stack, queue, linked list, etc.
Static data structure: Static data structure has a fixed memory size. It is easier to access the
elements in a static data structure.
An example of this data structure is an array.
Dynamic data structure: In dynamic data structure, the size is not fixed. It can be randomly updated
during the runtime which may be considered efficient concerning the memory (space) complexity of
the code.
Examples of this data structure are queue, stack, linked lists etc.
Non-linear data structure: Data structures where data elements are not placed sequentially or
linearly are called non-linear data structures. In a non-linear data structure, we can’t traverse all the
elements in a single run only.
Examples of non-linear data structures are trees and graphs.
Need Of Data structure:
The structure of the data and the synthesis of the algorithm are relative to each other. Data
presentation must be easy to understand so the developer, as well as the user, can make an efficient
implementation of the operation.
Data structures provide an easy way of organizing, retrieving, managing, and storing data.
Here is a list of the needs for data Structure.
1. Data structure modification is easy.
2. It requires less time.
3. Save storage memory space.
4. Data representation is easy.
5. Easy access to the large database.
LINKED LISTS
Like Arrays, a linked list is a linear data structure in which elements are not stored at contiguous
memory locations. The elements in a linked list are linked using pointers as shown in the below
image:
Example:
In a system, if we maintain a sorted list of IDs in an array id[] = [1000, 1010, 1050, 2000, 2040].
If we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the
elements after 1000 (excluding 1000).
Deletion is also expensive with arrays until unless some special techniques are used. For example, to
delete 1010 in id[], everything after 1010 has to be moved due to this so much work is being done
which affects the efficiency of the code.
ADVANTAGES OF LINKED LISTS OVER ARRAYS:
• Dynamic Array.
• Ease of Insertion/Deletion.
• Insertion at the beginning is a constant time operation and takes O(1) time, as compared to
arrays where inserting an element at the beginning takes O(n) time,where n is the number of
elements in the array.
DRAWBACKS OF LINKED LISTS:
• Random access is not allowed. We have to access elements sequentially starting from the
first node(head node). So we cannot do a binary search with linked lists efficiently with its
default implementation.
• Extra memory space for a pointer is required with each element of the list.
• Not cache-friendly. Since array elements are contiguous locations, there is the locality of
reference which is not there in the case of linked lists.
• It takes a lot of time in traversing and changing the pointers.
• Reverse traversing is not possible in singly linked lists.
• It will be confusing when we work with pointers.
• Direct access to an element is not possible in a linked list as in an array by index.
• Searching for an element is costly and requires O(n) time complexity.
• Sorting of linked lists is very complex and costly.
• Appending an element to a linked list is a costly operation, and takes O(n) time, where n is
the number of elements in the linked list, as compared to arrays that take O(1) time.
• TYPES OF LINKED LISTS:
1. Singly-linked list
2. Doubly linked list
3. Circular linked list
4. Doubly circular linked list
In addition, playlists can be shared with others, allowing users to share their music preferences with
friends and family. Sharing playlists can be a great way to bond with others over shared music tastes
or introduce friends to new artists or genres. It can also be a fun way to collaborate with others on a
playlist and create something that everyone can enjoy.
Moreover, playlists can be used for different purposes. For example, a workout playlist can help
motivate someone during their fitness routine, while a study playlist can help them focus and
concentrate better. A party playlist can set the mood for a social gathering, while a relaxing playlist
can help someone unwind after a long day.
In conclusion, playlists are a versatile and convenient feature that music applications offer to their
users. They allow users to customize their listening experience, discover new music, share their
musical tastes, and enhance their moods and activities.
This Project will help you to understand the basic operations on linked list such as adding, removing
and iterating a linked list forward and backward by using a real-world problem i.e PlayList. The main
motive of this project is to clear the operations of linked list like adding elements,deleting
elements,iterating a linked list,etc
3. ALGORITHM
16. Traverse the playlist using a while loop and print the songTitle and artistName of each
node.
End of Algorithm
4. CODE
struct Node {
char* songTitle;
char* artistName;
struct Node* next;
};
struct Playlist {
struct Node* head;
};
if (playlist->head == NULL) {
playlist->head = newNode;
} else {
struct Node* current = playlist->head;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
}
}