Data Structure Assignment Shruti Gupta
Data Structure Assignment Shruti Gupta
LABORATORY ASSIGNMENT
CT10212: DATA STRUCTURES
2024-2026
MCA I YEAR
Semester – I
1
Question No. 1
In computer science and computer programming, a data structure might be selected or designed
to store data for the purpose of using it with various algorithms -- commonly referred to as data
structures and algorithms (DSA). In some cases, the algorithm's basic operations are tightly
coupled to the data structure's design. Each data structure contains information about the data
values; relationships between the data; and, in some cases, functions that can be applied to the
data.
Efficiency: Data structures allow for efficient storage and retrieval of data, which is
important in applications where performance is critical.
Flexibility: Data structures provide a flexible way to organize and store data, allowing
for easy modification and manipulation.
Reusability: Data structures can be used in multiple programs and applications, reducing
the need for redundant code.
Abstraction: The data structure specified by an ADT also provides the level of
abstraction. The client cannot see the internal working of the data structure, so it does not
have to worry about the implementation part. The client can only see the interface.
2
Question No. 2
These data structures can be manipulated or operated directly by machine-level instructions the
Primitive Data Structures.
These data types are also called Simple data types, as they contain characters that can't be
divided further
3
2. Non-Primitive Data Structures:
Non-Primitive Data Structures are those data structures derived from Primitive Data Structures.
The focus of these data structures is on forming a set of data elements that is either homogeneous
(same data type) or heterogeneous (different data types).
Based on the structure and arrangement of data, we can divide these data structures into two sub-
categories -
Based on memory allocation, the Linear Data Structures are further classified into two types:
4
Types of Linear Data Structures:
The following is the list of Linear Data Structures that we generally use:
1. Arrays
An Array is a data structure used to collect multiple data elements of the same data type into one
variable. Instead of storing multiple values of the same data types in separate variable names, we
could store all of them together into one variable.
2. Linked Lists:
A Linked List is another example of a linear data structure used to store a collection of data
elements dynamically. Data elements in this data structure are represented by the Nodes,
connected using links or pointers. Each node contains two fields, the information field consists of
the actual data, and the pointer field consists of the address of the subsequent nodes in the list.
The pointer of the last node of the linked list consists of a null pointer, as it points to nothing.
Unlike the Arrays, the user can dynamically adjust the size of a Linked List as per the
requirements.
3. Stacks:
A Stack is a Linear Data Structure that follows the LIFO (Last In, First Out) principle that allows
operations like insertion and deletion from one end of the Stack, i.e., Top. Stacks can be
implemented with the help of contiguous memory, an Array, and non-contiguous memory, a
Linked List. Real-life examples of Stacks are piles of books, a deck of cards, piles of money, and
many more.
5
The primary operations in the Stack are as follows:
Push: Operation to insert a new element in the Stack is termed as Push Operation.
Pop: Operation to remove or delete elements from the Stack is termed as Pop Operation.
4. Queues
A Queue is a linear data structure similar to a Stack with some limitations on the insertion and
deletion of the elements. The insertion of an element in a Queue is done at one end, and the
removal is done at another or opposite end. Thus, we can conclude that the Queue data structure
follows FIFO (First In, First Out) principle to manipulate the data elements. Implementation of
Queues can be done using Arrays, Linked Lists, or Stacks. Some real-life examples of Queues
are a line at the ticket counter, an escalator, a car wash, and many more.
1. Trees
A Tree is a Non-Linear Data Structure and a hierarchy containing a collection of nodes such that
each node of the tree stores a value and a list of references to other nodes (the "children").
6
The Tree data structure is a specialized method to arrange and collect data in the computer to be
utilized more effectively. It contains a central node, structural nodes, and sub-nodes connected
via edges. We can also say that the tree data structure consists of roots, branches, and leaves
connected.
2. Graph
A Graph is another example of a Non-Linear Data Structure comprising a finite number of nodes
or vertices and the edges connecting them. The Graphs are utilized to address problems of the
real world in which it denotes the problem area as a network such as social networks, circuit
networks, and telephone networks. For instance, the nodes or vertices of a Graph can represent a
single user in a telephone network, while the edges represent the link between them via
telephone.
The Graph data structure, G is considered a mathematical structure comprised of a set of vertices,
V and a set of edges, E as shown below:
G = (V, E)
3. Hash Table
A hash table is a structure that stores key-value pairs, allowing for fast data retrieval using a key.
It works as the key is passed through a hash function which converts it to an index that
corresponds to the location of the value in memory.
Features:
Fast access and insertion, collision handling through chaining or open
addressing.
A dictionary where you can quickly look up the definition of a word is an
example of hash function
It is suitable for applications requiring fast lookups, like caching or
implementing associative arrays.
7
Question No. 3
1 In a linear data structure, data elements are In a non-linear data structure, data elements are
arranged in a linear order where each and attached in hierarchically manner.
every element is attached to its previous
and next adjacent
2 In linear data structure, single level is Whereas in non-linear data structure, multiple
involved. levels are involved.
4 In linear data structure, data elements can While in non-linear data structure, data elements
be traversed in a single run only. can’t be traversed in a single run only.
5 In a linear data structure, memory is not While in a non-linear data structure, memory is
utilized in an efficient way utilized in an efficient way.
6 Performance is usually good for simple Performance can vary depending on the structure
operations like adding or removing at the and the operation, but can be optimized for
ends, but slower for operations like specific operations.
searching or removing elements in the
middle.
7 Its examples are: array, stack, queue, linked While its examples are: trees and graphs.
list, etc.
8 Applications of linear data structures are Applications of non-linear data structures are in
mainly in application software Artificial Intelligence and image processing.
development.
8
Question No. 4
In a nutshell, data can be a number, symbol, character, word, codes, graphs, etc. On the other
hand, information is data put into context. Information is utilized by humans in some significant
way (such as to make decisions, forecasts etc.).
Data Information
Data is unorganized and unrefined facts Information comprises processed, organized
data presented in a meaningful context
Data is an individual unit that contains raw Information is a group of data that collectively
materials which do not carry any specific carries a logical meaning
meaning
Raw data alone is insufficient for decision Information is sufficient for decision making
making
An example of data is a student’s test score The average score of a class is the information
derived from the given data.
9
Question No. 5
What is Abstract Data Type? Explain ADT on Stack, Queue, and Linked List .
In other words, an ADT provides only the interface to which the data structure must adhere. The
interface does not give specific details about what should be implemented or in what
programming language.
In every programming language, ADTs are implemented using different methods and logic. In C
that ADTs are implemented mostly using structure. Whereas in C++ or JAVA, they’re
implemented using class. However, operations are common in all languages.
1. Stack ADT
A stack is a special type of list that allows insertions and removals to be performed only to the
front of the list. Therefore, it enforces Last-in–First out (LIFO) behavior on the list. Think of a
stack of dishes at the salad bar. When you put a dish on the stack, it goes onto the top of the stack.
When you remove a dish from the stack, it comes from the top of the stack.
The stack operations are conventionally called push, for insert, and pop, for remove, respectively.
Thus, the stack ADT stores a list of data and supports the following operations:
2. Pop: Removes the top element from the stack and returns it.
Example: pop() → returns 20, stack is now [10]
3. Peek/Top: Looks at the top element of the stack without removing it.
Example: peek() → returns 10 (top element)
4. isEmpty: Checks if the stack has no elements.
Example: isEmpty() → returns false (because the stack still has elements)
10
5. isFull: For stacks with a fixed capacity, this checks if the stack has reached its
maximum size.
Example: isEmpty() → returns false (because the stack is not full)
2. Queue ADT
A queue is a linear data structure where elements are stored in the FIFO (First In First Out)
principle where the first element inserted would be the first element to be accessed. A queue is
an Abstract Data Type (ADT) similar to stack, the thing that makes queue different from stack is
that a queue is open at both its ends. The data is inserted into the queue through one end and
deleted from it using the other end. Queue is very frequently used in most programming
languages.
Operations of a Queue:
2. Dequeue: Removes the element from the front of the queue and returns it.
Example: dequeue() → returns 5, queue becomes [10, 15]
3. Front/Peek: Returns the element at the front of the queue without removing it.
Example: peek() → returns 10 (the current front element), queue remains [10, 15]
5. isFull: For queues with a fixed capacity, this checks if the queue has reached its maximum
size.
11