0% found this document useful (0 votes)
4 views18 pages

Data Structure Types, Classifications and Applications

Data structures are essential for organizing, processing, and storing data efficiently in computer systems. They can be classified into linear (e.g., arrays, stacks, queues) and non-linear (e.g., trees, graphs) types, each with distinct characteristics and applications. Additionally, the document discusses concepts like time and space complexity, as well as Abstract Data Types (ADTs), which encapsulate data and operations while providing abstraction and modularity.
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)
4 views18 pages

Data Structure Types, Classifications and Applications

Data structures are essential for organizing, processing, and storing data efficiently in computer systems. They can be classified into linear (e.g., arrays, stacks, queues) and non-linear (e.g., trees, graphs) types, each with distinct characteristics and applications. Additionally, the document discusses concepts like time and space complexity, as well as Abstract Data Types (ADTs), which encapsulate data and operations while providing abstraction and modularity.
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/ 18

Data Structure Types, Classifications and Applications

What is Data Structure:

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. Different basic and advanced
types of data structures are used in almost every program or software
system that has been developed. So we must have good knowledge of
data structures.

Data structures are an integral part of computers used for the


arrangement of data in memory. They are essential and responsible for
organizing, processing, accessing, and storing data efficiently. But this is
not all. Various types of data structures have their characteristics,
features, applications, advantages, and disadvantages. So how do you
identify a data structure that is suitable for a particular task? What is
meant by the term ‘Data Structure’? How many types of data structures
are there and what are they used for?

Classification of Data Structure:

Data structure has many different uses in our daily life. There are many
different data structures that are used to solve different mathematical and
logical problems. By using data structure, one can organize and process
a very large amount of data in a relatively short period. Let’s look at
different data structures that are used in different situations.

Classification of Data Structure

 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.

o 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.

o Dynamic data structure: In the 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, 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.

Arrays:

An array is a linear data structure and it is a collection of items stored at


contiguous memory locations. The idea is to store multiple items of the
same type together in one place. It allows the processing of a large
amount of data in a relatively short period. The first element of the array
is indexed by a subscript of 0. There are different operations possible in
an array, like Searching, Sorting, Inserting, Traversing, Reversing, and
Deleting.

Array

Characteristics of an Array:

An array has various characteristics which are as follows:

 Arrays use an index-based data structure which helps to identify


each of the elements in an array easily using the index.

 If a user wants to store multiple values of the same data type, then
the array can be utilized efficiently.
 An array can also handle complex data structures by storing data in
a two-dimensional array.

 An array is also used to implement other data structures like


Stacks, Queues, Heaps, Hash tables, etc.

 The search process in an array can be done very easily.

Linked list:

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:

Types of linked lists:

 Singly-linked list

 Doubly linked list

 Circular linked list

 Doubly circular linked list

Linked List

Characteristics of a Linked list:

A linked list has various characteristics which are as follows:

 A linked list uses extra memory to store links.

 During the initialization of the linked list, there is no need to know


the size of the elements.

 Linked lists are used to implement stacks, queues, graphs, etc.

 The first node of the linked list is called the Head.

 The next pointer of the last node always points to NULL.


 In a linked list, insertion and deletion are possible easily.

 Each node of the linked list consists of a pointer/link which is the


address of the next node.

 Linked lists can shrink or grow at any point in time easily.

Stack:

Stack is a linear data structure that follows a particular order in which


the operations are performed. The order is LIFO(Last in first out).
Entering and retrieving data is possible from only one end. The entering
and retrieving of data is also called push and pop operation in a stack.
There are different operations possible in a stack like reversing a stack
using recursion, Sorting, Deleting the middle element of a stack, etc.

Stack

Characteristics of a Stack:

Stack has various different characteristics which are as follows:

 Stack is used in many different algorithms like Tower of Hanoi,


tree traversal, recursion, etc.

 Stack is implemented through an array or linked list.

 It follows the Last In First Out operation i.e., an element that is


inserted first will pop in last and vice versa.

 The insertion and deletion are performed at one end i.e. from the
top of the stack.

 In stack, if the allocated space for the stack is full, and still anyone
attempts to add more elements, it will lead to stack overflow.

Queue:

Queue is a linear data structure that follows a particular order in which


the operations are performed. The order is First In First Out(FIFO) i.e.
the data item stored first will be accessed first. In this, entering and
retrieving data is not done from only one end. An example of a queue is
any queue of consumers for a resource where the consumer that came
first is served first. Different operations are performed on a Queue like
Reversing a Queue (with or without using recursion), Reversing the first
K elements of a Queue, etc. A few basic operations performed In Queue
are enqueue, dequeue, front, rear, etc.

Queue

Characteristics of a Queue:

The queue has various different characteristics which are as follows:

 The queue is a FIFO (First In First Out) structure.

 To remove the last element of the Queue, all the elements inserted
before the new element in the queue must be removed.

 A queue is an ordered list of elements of similar data types.

Tree

Characteristics of a Tree:

The tree has various different characteristics which are as follows:

 A tree is also known as a Recursive data structure.

 In a tree, the Height of the root can be defined as the longest path
from the root node to the leaf node.

 In a tree, one can also calculate the depth from the top to any node.
The root node has a depth of 0.

Graph:

A graph is a non-linear data structure that consists of vertices (or nodes)


and edges. It consists of a finite set of vertices and set of edges that
connect a pair of nodes. The graph is used to solve the most challenging
and complex programming problems. It has different terminologies
which are Path, Degree, Adjacent vertices, Connected components, etc.
Graph

Characteristics of Graph:

The graph has various different characteristics which are as follows:

 The maximum distance from a vertex to all the other vertices is


considered the Eccentricity of that vertex.

 The vertex having minimum Eccentricity is considered the central


point of the graph.

 The minimum value of Eccentricity from all vertices is considered


the radius of a connected graph.

Time Complexity and Space Complexity

Many times there are more than one ways to solve a problem with
different algorithms and we need a way to compare multiple ways. Also,
there are situations where we would like to know how much time and
resources an algorithm might take when implemented. To measure
performance of algorithms, we typically use time and space complexity
analysis. The idea is to measure order of growths in terms of input size.

 Independent of the machine and its configuration, on which the


algorithm is running on.

 Shows a direct correlation with the number of inputs.

 Can distinguish two algorithms clearly without ambiguity.

Time Complexity: The time complexity of an algorithm quantifies the


amount of time taken by an algorithm to run as a function of the length
of the input. Note that the time to run is a function of the length of the
input and not the actual execution time of the machine on which the
algorithm is running on.

The valid algorithm takes a finite amount of time for execution. The
time required by the algorithm to solve given problem is called time
complexity of the algorithm. Time complexity is very useful measure in
algorithm analysis.

It is the time needed for the completion of an algorithm. To estimate the


time complexity, we need to consider the cost of each fundamental
instruction and the number of times the instruction is executed.

Example 1: Addition of two scalar variables.

Algorithm ADD SCALAR(A, B)


//Description: Perform arithmetic addition of two numbers
//Input: Two scalar variables A and B
//Output: variable C, which holds the addition of A and B
C <- A + B

Space Complexity:

Definition –

Problem-solving using computer requires memory to hold temporary


data or final result while the program is in execution. The amount of
memory required by the algorithm to solve given problem is called
space complexity of the algorithm.

The space complexity of an algorithm quantifies the amount of space


taken by an algorithm to run as a function of the length of the input.
Consider an example: Suppose a problem to find the frequency of array
elements.

It is the amount of memory needed for the completion of an algorithm.

To estimate the memory requirement we need to focus on two parts:

(1) A fixed part: It is independent of the input size. It includes memory


for instructions (code), constants, variables, etc.

(2) A variable part: It is dependent on the input size. It includes


memory for recursion stack, referenced variables, etc.

Example : Addition of two scalar variables


Algorithm ADD SCALAR(A, B)
//Description: Perform arithmetic addition of two numbers
//Input: Two scalar variables A and B
//Output: variable C, which holds the addition of A and B
C <— A+B
return C

1.what is Abstract Data Type? Advantages and


Disadvantages of Abstract Data Type?
In this article, we will learn about ADT but before understanding what
ADT is let us consider different in-built data types that are provided to
us. Data types such as int, float, double, long, etc. are considered to be
in-built data types and we can perform basic operations with them
such as addition, subtraction, division, multiplication, etc. Now there
might be a situation when we need operations for our user-defined
data type which have to be defined. These operations can be defined
only as and when we require them. So, in order to simplify the
process of solving problems, we can create data structures along with
their operations, and such data structures that are not in-built are
known as Abstract Data Type (ADT).
Abstract Data type (ADT) is a type (or class) for objects whose
behaviour is defined by a set of values and a set of operations. The
definition of ADT only mentions what operations are to be performed
but not how these operations will be implemented. It does not specify
how data will be organized in memory and what algorithms will be
used for implementing the operations. It is called “abstract” because it
gives an implementation-independent view.
The process of providing only the essentials and hiding the details is
known as abstraction.
The user of data type does not need to know how that data type is
implemented, for example, we have been using Primitive values like
int, float, char data types only with the knowledge that these data type
can operate and be performed on without any idea of how they are
implemented.
So, a user only needs to know what a data type can do, but not how it
will be implemented. Think of ADT as a black box which hides the
inner structure and design of the datatype. Now we’ll define three
ADTs namely ListADT, StackADT, QueueADT.
1. List ADT

VIEW OF LIST

 The data is generally stored in key sequence in a list which


has a head structure consisting of count, pointers and addres
of compare function needed to compare the data in the list.
 The data node contains the pointer to a data structure and a
self- referential pointer which points to the next node in the
list.
 The List ADT Functions is given below:
 get()–Returnanelementfromthelistatanygivenposition.
 insert()–Insertanelementatanypositionofthelist.
 remove () – Remove the first occurrence of any element from
a non-empty list.
 remove at () – Remove the element at a specified location
from a non- empty list.
 replace()–Replaceanelementatanypositionbyanotherelement.
 size()–Returnthenumberofelementsinthelist.
 isEmpty()–Returntrueifthelistisempty,otherwisereturnfalse.
 isFull()–Returntrueifthelistisfull,otherwisereturnfalse.

2. StackADT
Viewofstack

 InStackADTImplementationinsteadofdatabeingstoredineach
node, the pointer to data is stored.
 The program allocatesmemory for the data and address is
passedto the stack ADT.
 The head node and the data nodes are encapsulated in the
ADT. Thecalling function can only see the pointer to the
stack.
 Thestackheadstructurealsocontainsapointerto top and count of
number of entries currently in stack.
 push()–Insertanelementatoneendofthestackcalledtop.
 pop () – Remove and return the element at the top of the
stack, if it is not empty.
 peek () – Return the element at the top of the stack without
removing it, if the stack is not empty.
 size()–Returnthenumberofelementsinthestack.
 isEmpty()–Returntrueifthestackisempty,otherwisereturnfalse.
 isFull()–Returntrueifthestackisfull,otherwisereturnfalse.

3. QueueADT
View of Queue

 The queue abstract data type (ADT) follows the basic design
of the stack abstract data type.
 Each node contains a void pointer to the data and the link
pointer to the next element in the queue. The program’s
responsibility is to allocate memory for storing the data.
 enqueue ()–Insert an element at the end of the queue.
 dequeue () – Remove and return the first element of the
queue, if thequeue is not empty.
 peek () – Return the element of the queue without removing
it, if thequeue is not empty.
 size()– Return the number of elements in the queue.
 isEmpty()– Return true if the queue is empty, other wise return
false.
 is Full () – Return true if the queue is full, otherwise
return false. Features of ADT:
Abstract data types (ADTs) areaway of encapsulating data and
operations on that data into a single unit. Some of the key features
of ADTs include:
 Abstraction: The user does not need to know the
implementation of the data structure only essentials are
provided.
 Better Conceptualization: ADT gives us a better
conceptualization of the real world.
 Robust: The program is robust and has the ability to catch
errors.
 Encapsulation: ADTs hide the internal details of the data
and provide a public interface for users to interact with the
data. This allows for easier maintenance and modification of
the data structure.
 Data Abstraction: ADTs provide a level of abstraction from
the implementation details of the data. Users only need to
know the operations that can be performed on the data, not
how those operations are implemented.
 Data Structure Independence: ADTs can be implemented
using different data structures, such as arrays or linked lists,
without affecting the functionality of the ADT.
 Information Hiding: ADTs can protect the integrity of the
data by allowing access only to authorized users and
operations. This helps prevent errors and misuse of the data.
 Modularity: ADTs can be combined with other ADTs to
form larger, more complex data structures. This allows for
greater flexibility and modularity in programming.
Overall, ADTs provide a powerful tool for organizing and
manipulating data ina structured and efficient manner.

Abstract data types(ADTs) have several advantages and disadvantages


that should be considered when deciding to use the min software
development. Here are some of the main advantages and
disadvantages of using ADTs: Advantages:
 Encapsulation: ADTs provide a way to encapsulate data and
operations into a single unit, making it easier to manage and
modify the data structure.
 Abstraction: ADTs allow users to work with data structures
without having to know the implementation details, which
can simplify programming and reduce errors.
 Data Structure Independence: ADTs can be implemented
using different data structures, which can make it easier to
adapt to changing needs and requirements.
 Information Hiding: ADTs can protect the integrity of data
by controlling access and preventing unauthorized
modifications.
 Modularity: ADTs can be combined with other ADTs to
form more complex data structures, which can increase
flexibility and modularity in programming.
Disadvantages:
 Overhead: Implementing ADTs can add overhead in terms
of memory and processing, which can affect performance.
 Complexity: ADTs can be complex to implement, especially
for large and complex data structures.
 Learning Curve:Using ADTs requires knowledge of
their implementation and usage, which can
take time and effort to learn.
 Limited Flexibility: Some ADTs may be limited in their
functionality or may not be suitable for all types of data
structures.
 Cost: Implementing ADTs may require additional resources
and investment, which can increase the cost of development.

1.Difference between Abstract data type and data type?


S. Abstract Data Types or Concrete Data Types
No. structure or structure
(ADT) (CDT)
Concrete data types or
Abstract Data Types or structures structures provide
1 describe the data and the how these operations
operations to manipulate and are actually
change it. implemented.
Most of the program becomes
independent of the abstract data Which is not possible in
2 types representation,so it can be Concrete Data Types or
improved without breaking the structure (CDT)
program.
It’s easier for each part of a
3 program to use an It is not so efficient
implementation of its data types compared to
and that will be more efficient. ADT.

Implementation of a
4 Implementationofahighlevelconce simple concept
pt
It is rarely reusable
5 Itisusablebeyonditsoriginaluse. beyond its
original use.
6 Ithidestheinternaldetails. Itdoesn’thideanything.

7 Itusesclass. Itusesstructure.

Examples-Arrays,
8 Examples-lists,sets,stacks. linked lists, trees,
graphs.

SEARCHING
Searching is the fundamental process of locating a specific element or item within a collection of
data. This collection of data can be arrays, lists, trees, or other structured representations. Data
structures are complex systems designed to organize vast amounts of information. Searching
within a data structure is one of the most critical operations performed on stored data.

The goal is to find the desired information with its precise location quickly and with minimal
computational resources. It plays an important role in various computational tasks and real-world
applications, including information retrieval, data analysis, decision-making processes, etc.

Searching Techniques: Linear Search and Binary Search


Linear Search
1. Start at the beginning of the list.
2. Compare the target value with the current element in the list.
3. If the current element matches the target value, the search is successful, and the position or
index of the element is returned.
4. If the current element does not match the target value, move to the next element in the list.
5. Repeat steps 2-4 until a match is found or the end of the list is reached.
6. If the end of the list is reached without finding a match, the search is unsuccessful, and a special
value (e.g., -1) may be returned to indicate the absence of the target value

Binary Search
1. Start with a sorted array or list. For binary search to work correctly, the elements must be in
ascending or descending order.
2. Set two pointers, low and high, to the beginning and end of the search space, respectively.
Initially, low = 0 and high = length of the array - 1.
3. Calculate the middle index using the formula: mid = (low + high) / 2. This will give you the index
of the element in the middle of the current search space.
4. Compare the target value with the element at the middle index:
o If they are equal, the target value has been found. Return the index of the middle
element.
o If the target value is less than the middle element, set high = mid - 1 and go to step 3.
o If the target value is greater than the middle element, set low = mid + 1 and go to step
3.
5. Repeat steps 3-4 until the target value is found or low > high. If low becomes greater than high,
it means the target value is not present in the array.

SORTING
Sorting in data structures helps arrange elements in a specific order, making
it easier to search, analyze, and visualize information. Let’s learn about
the various types of sorting algorithms, their workings, and their importance
in solving real-world problems.

Uses and Importance of Data Structure Sorting


The main purpose of sorting algorithms is to make data easier to work with. When data is
sorted, it becomes faster to search for items, easier to read, and more efficient to process.

For example, finding a name in a sorted list is quicker than finding it in an unsorted list.
Sorting is also important because it is often a first step in many other algorithms and data
operations.

Bubble Sort
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list to be sorted,
compares adjacent elements, and swaps them if they are in the wrong order. The process is
repeated until the list is sorted. It is called Bubble Sort because smaller elements "bubble"
to the top of the list.

Example:
Consider the list [4, 2, 7, 1].

First pass:
 Compare 4 and 2, swap to get [2, 4, 7, 1]
 Compare 4 and 7, no swap
 Compare 7 and 1, swap to get [2, 4, 1, 7]

Second pass:
 Compare 2 and 4, no swap
 Compare 4 and 1, swap to get [2, 1, 4, 7]

Third pass:
 Compare 2 and 1, swap to get [1, 2, 4, 7]

Fourth pass:
 List is already sorted, no swaps needed
Final sorted list: [1, 2, 4, 7].

Use Cases of Bubble Sorting


 Used to teach the basics of sorting algorithms and algorithm analysis due to its
simplicity.
 Suitable for small datasets where its simplicity outweighs its inefficiency.
 Performs well on data that is already partially sorted, as it can quickly detect the
order and terminate early

Selection Sort
Selection Sort is a simple comparison-based sorting algorithm. It divides the list into two
parts: the sorted part at the beginning and the unsorted part at the end.

The algorithm repeatedly selects the smallest (or largest, depending on sorting order)
element from the unsorted part and swaps it with the first element of the unsorted part,
effectively growing the sorted part by one element with each iteration.

Example:
Consider the list [4, 2, 7, 1].

First pass:
 Find the minimum element in [4, 2, 7, 1], which is 1
 Swap 1 with 4 to get [1, 2, 7, 4]

Second pass:
 Find the minimum element in [2, 7, 4], which is 2
 Swap 2 with 2 to get [1, 2, 7, 4] (no change)

Third pass:
 Find the minimum element in [7, 4], which is 4
 Swap 4 with 7 to get [1, 2, 4, 7]

Fourth pass:
 The last element 7 is already in place, no need to swap
 Final sorted list: [1, 2, 4, 7].

Insertion Sort
Insertion Sort is a simple comparison-based sorting algorithm that builds the final sorted
list one element at a time. It works similarly to the way you might sort playing cards in your
hands.

The algorithm takes one element from the unsorted portion of the list and inserts it into its
correct position in the sorted portion. This process is repeated until the entire list is sorted.

Example:
Consider the list [4, 2, 7, 1].
First pass (i = 1):
 Key is 2. Compare 2 with 4.
 2 is less than 4, so move 4 to the right and insert 2 at the beginning to get [2, 4, 7, 1].

Second pass (i = 2):


 Key is 7. Compare 7 with 4.
 7 is greater than 4, so no movement needed. List remains [2, 4, 7, 1].

Third pass (i = 3):


 Key is 1. Compare 1 with 7, 4, and 2.
 1 is less than 7, move 7 to the right.
 1 is less than 4, move 4 to the right.
 1 is less than 2, move 2 to the right.
 Insert 1 at the beginning to get [1, 2, 4, 7].

Final sorted list: [1, 2, 4, 7].

You might also like