SlideShare a Scribd company logo
21CSC201J
DATA STRUCTURES AND
ALGORITHMS
UNIT-1
DATA STRUCTURE
OPERATIONS
Data Structure Operations
• The data in the data structures are processed by certain operations.
o Traversing
o Searching
o Inserting
o Updating
o Deleting
o Sorting
o Merging
Data Structure Operations (Cont..)
• Traversing - Visiting each record so that items in the records can be accessed.
• Searching - Finding the location of the record with a given key or value or finding
all records which satisfy given conditions.
• Inserting - Adding a new record to the data structure.
• Updating – Change the content of some elements of the record.
• Deleting - Removing records from the data structure.
• Sorting - Arranging records in some logical or numerical order.
o (Eg: Alphabetic order)
• Merging - Combing records from two different sorted files into a single file.
Example
• An organization contains a membership file in which each record contains the
following data for a given member:
Name, Address, Telephone Number, Age, Sex
a. Suppose the organization wants to announce a meeting through a mailing.
Then one would traverse the file to obtain Name and Address of each
member.
b. Suppose one wants to find the names of all members living in a particular
area. Again traverse and search the file to obtain the data.
c. Suppose one wants to obtain Address of a specific Person. Then one would
search the file for the record containing Name.
d. Suppose a member dies. Then one would delete his or her record from the
file.
Example
e. Suppose a new person joins the organization. Then one would insert a
record into the file
f. Suppose a member has shifted to a new residence his/her address and
telephone number need to be changed. Given the name of the member, one
would first need to search for the record in the file. Then perform the
update operation, i.e. change some items in the record with the new data.
g. Suppose one wants to find the number of members whose age is 65 or above.
Again one would traverse the file, counting such members.
ABSTRACT DATA TYPE
Abstract Data Types
• An Abstract Data type (ADT) is a type for objects whose behavior is defined by a
set of value and a set of operations.
• ADT refers to a set of data values and associated operations that are specified
accurately, independent of any particular implementation.
• The ADT consists of a set of definitions that allow us to use the functions while
hiding the implementation.
• Abstract in the context of data structures means everything except the detailed
specifications or implementation.
• Data type of a variable is the set of values that the variable can take.
• Examples: Stacks, Queues, Linked List
ADT = Type + Function Names + Behaviour of each function
ADT Operations
• While modeling the problems the necessary details are separated out from the
unnecessary details. This process of modeling the problem is called abstraction.
• The model defines an abstract view to the problem. It focuses only on problem
related stuff and that you try to define properties of the problem.
• These properties include
o The data which are affected.
o The operations which are identified.
ADT Operations ( Cont..)
• Abstract data type operations are
o Create - Create the data structure.
o Display - Displaying all the elements stored in the data structure.
o Insert - Elements can be inserted at any desired position.
o Delete - Desired element can be deleted from the data structure.
o Modify - Any desired element can be deleted/modified from the data structure.
Abstract Data Types Model
• The ADT model has two different parts
functions (public and private) and data
structures.
• Both are contained within the ADT model itself,
and do not come within the scope of the
application program.
• Data structures are available to all of the ADT’s
functions as required, and a function may call
any other function to accomplish its task.
• Data structures and functions are within the scope
of each other.
Abstract Data Types Model (Cont..)
• Data are entered, accessed, modified and
deleted through the external application
programming interface.
• For each ADT operation, there is an algorithm
that performs its specific task.
• The operation name and parameters are
available to the application, and they provide
only an interface to the application.
• When a list is controlled entirely by the
program, it is implemented using simple
structure.
Review Questions
• ______ are used to manipulate the data contained in various data structures.
• In ______, the elements of a data structure are stored sequentially.
• ______ of a variable specifies the set of values that the variable can take.
• Abstract means ______.
• If the elements of a data structure are stored sequentially, then it is a ______.
ALGORITHMS
SEARCHING TECHIQUES
Algorithms
• An algorithm is a well defined list of steps for solving a particular problem.
• The time and space are two major measures of the efficiency of an algorithm.
• The complexity of an algorithm is the function which gives the running time and /
or space in terms of input size.
Searching Algorithms
• Searching Algorithms are designed to check for an element or retrieve an element
from any data structure where it is stored.
• Based on the type of search operation, these algorithms are generally classified
into two categories:
• Linear Search
• Binary Search
Linear Search
• Linear search is a very basic and simple search algorithm.
• In Linear search, we search an element or value in a given array by traversing the
array from the starting, till the desired element or value is found or we can
establish that the element is not present.
• It compares the element to be searched with all the elements present in the array
and when the element is matched successfully, it returns the index of the element
in the array, else it return -1.
• Linear search is applied on unsorted or unordered lists, when there are fewer
elements in a list.
Linear Search - Example
• Search each record of the file, one at a time, until finding the given value.
Algorithm for Linear Search
• In Steps 1 and 2 of the algorithm, we initialize the
value of POS and I.
• In Step 3, a while loop is executed that would be
executed till I is less than N.
• In Step 4, a check is made to see if a match is
found between the current array element and VAL.
• If a match is found, then the position of the array
element is printed, else the value of I is
incremented to match the next element with VAL.
• If all the array elements have been compared with
VAL and no match is found, then it means that
VAL is not present in the array.
Program for Linear Search
Linear Search - Advantages
• When a key element matches the first element in the array, then linear search
algorithm is best case because executing time of linear search algorithm is O(n),
where n is the number of elements in an array.
• The list doesn’t have to sort. Contrary to a binary search, linear searching does not
demand a structured list.
• Not influenced by the order of insertions and deletions. Since the linear search
doesn’t call for the list to be sorted, added elements can be inserted and deleted.
Linear Search - Disadvantages
• The drawback of a linear search is the fact that it is time consuming if the size of
data is huge.
• Every time a vital element matches the last element from the array or an essential
element does not match any element Linear search algorithm is the worst case.
Binary Search
• Binary Search is used with sorted array or list. In binary search, we follow the
following steps:
1) We start by comparing the element to be searched with the element in the
middle of the list/array.
2) If we get a match, we return the index of the middle element and terminate
the process
3) If the element/number to be searched is greater than the middle element, we
pick the elements on the left/right side of the middle element, and move to
step 1.
4) If the element/number to be searched is lesser in value than the middle
number, then we pick the elements on the right/left side of the middle
element, and move to step 1.
Binary Search - Example
• Binary Search is useful when there are large number of elements in an array and
they are sorted.
Algorithm for Binary Search
• In Step 1, we initialize the value of variables, BEG,
END, and POS.
• In Step 2, a while loop is executed until BEG is less
than or equal to END.
• In Step 3, the value of MID is calculated.
• In Step 4, we check if the array value at MID is equal to
VAL. If a match is found, then the value of POS is
printed and the algorithm exits. If a match is not found,
and if the value of A[MID] is greater than VAL, the
value of END is modified, otherwise if A[MID] is
greater than VAL, then the value of BEG is altered.
• In Step 5, if the value of POS = –1, then VAL is not
present in the array and an appropriate message is
printed on the screen before the algorithm exits.
Program for Binary Search
Binary Search (Cont..)
Advantages
• It eliminates half of the list from
further searching by using the result of
each comparison.
• It indicates whether the element being
searched is before or after the current
position in the list.
• This information is used to narrow the
search.
• For large lists of data, it works
significantly better than linear search.
Disadvantages
• It employs recursive approach which
requires more stack space.
• Programming binary search algorithm
is error prone and difficult.
• The interaction of binary search with
memory hierarchy i.e. caching is poor.
Difference between Linear & Binary Search
Linear Search
• Linear Search necessitates the input
information to be not sorted
• Linear Search needs equality
comparisons.
• Linear search has complexity C(n)=
n/2.
• Linear Search needs sequential access.
Binary Search
• Binary Search necessitates the input
information to be sorted.
• Binary Search necessitates an ordering
contrast.
• Binary Search has complexity C(n)=
log 2
n.
• Binary Search requires random access
to this information.
Ad

More Related Content

What's hot (20)

Parsing
ParsingParsing
Parsing
khush_boo31
 
Linked list
Linked listLinked list
Linked list
akshat360
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
Sangani Ankur
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Automata presentation turing machine programming techniques
Automata presentation turing machine programming techniquesAutomata presentation turing machine programming techniques
Automata presentation turing machine programming techniques
Basit Hussain
 
Passes of Compiler.pptx
Passes of Compiler.pptxPasses of Compiler.pptx
Passes of Compiler.pptx
Sanjay Singh
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 
Loop optimization
Loop optimizationLoop optimization
Loop optimization
Vivek Gandhi
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
Muthukumaran Subramanian
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
Archana Gopinath
 
Array and string
Array and stringArray and string
Array and string
prashant chelani
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
Abhilash Nair
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
Markajul Hasnain Alif
 
Circular queue
Circular queueCircular queue
Circular queue
Lovely Professional University
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
Aparna Joshi
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
Akhil Kaushik
 
Linked list
Linked listLinked list
Linked list
akshat360
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
Sangani Ankur
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Automata presentation turing machine programming techniques
Automata presentation turing machine programming techniquesAutomata presentation turing machine programming techniques
Automata presentation turing machine programming techniques
Basit Hussain
 
Passes of Compiler.pptx
Passes of Compiler.pptxPasses of Compiler.pptx
Passes of Compiler.pptx
Sanjay Singh
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 
Loop optimization
Loop optimizationLoop optimization
Loop optimization
Vivek Gandhi
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
Archana Gopinath
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
Abhilash Nair
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
Aparna Joshi
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
Akhil Kaushik
 

Similar to Data Structure & Algorithms - Operations (20)

CHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptxCHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptx
OnkarModhave
 
ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
GOOGLEINTERNETCAFE1
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 
Unit-I PPT hususi sisooshsgv. Eijeieieooekejj
Unit-I PPT hususi sisooshsgv.     EijeieieooekejjUnit-I PPT hususi sisooshsgv.     Eijeieieooekejj
Unit-I PPT hususi sisooshsgv. Eijeieieooekejj
sanketkurve7
 
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
Unit 1 OF DS FOR AI DS BTRCH  OF DS FOR AI DS BTRCH  .pdfUnit 1 OF DS FOR AI DS BTRCH  OF DS FOR AI DS BTRCH  .pdf
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
prathamsingh33
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
NathanielAdika
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
JohnStuart83
 
A Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching AlgorithmsA Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching Algorithms
IRJET Journal
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
cs702 ppt.ppt
cs702 ppt.pptcs702 ppt.ppt
cs702 ppt.ppt
JavedIqbal398171
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
mexiuro901
 
project on data structures and algorithm
project on data structures and algorithmproject on data structures and algorithm
project on data structures and algorithm
AnujKumar566766
 
Data strucutre basic introduction
Data strucutre basic introductionData strucutre basic introduction
Data strucutre basic introduction
manirajan12
 
Data structures list
Data structures listData structures list
Data structures list
Vijaya Kalavakonda
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta
 
Introduction to Data Structures and their importance
Introduction to Data Structures and their importanceIntroduction to Data Structures and their importance
Introduction to Data Structures and their importance
Bulbul Agrawal
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
removed_8057d320f6c8601c14a895598b86eacb
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
dsa.pptx
dsa.pptxdsa.pptx
dsa.pptx
Dr.Shweta
 
CHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptxCHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptx
OnkarModhave
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 
Unit-I PPT hususi sisooshsgv. Eijeieieooekejj
Unit-I PPT hususi sisooshsgv.     EijeieieooekejjUnit-I PPT hususi sisooshsgv.     Eijeieieooekejj
Unit-I PPT hususi sisooshsgv. Eijeieieooekejj
sanketkurve7
 
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
Unit 1 OF DS FOR AI DS BTRCH  OF DS FOR AI DS BTRCH  .pdfUnit 1 OF DS FOR AI DS BTRCH  OF DS FOR AI DS BTRCH  .pdf
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
prathamsingh33
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
NathanielAdika
 
A Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching AlgorithmsA Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching Algorithms
IRJET Journal
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
mexiuro901
 
project on data structures and algorithm
project on data structures and algorithmproject on data structures and algorithm
project on data structures and algorithm
AnujKumar566766
 
Data strucutre basic introduction
Data strucutre basic introductionData strucutre basic introduction
Data strucutre basic introduction
manirajan12
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta
 
Introduction to Data Structures and their importance
Introduction to Data Structures and their importanceIntroduction to Data Structures and their importance
Introduction to Data Structures and their importance
Bulbul Agrawal
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
dsa.pptx
dsa.pptxdsa.pptx
dsa.pptx
Dr.Shweta
 
Ad

More from babuk110 (7)

Deployment Models-Internet of things Materials
Deployment Models-Internet of things MaterialsDeployment Models-Internet of things Materials
Deployment Models-Internet of things Materials
babuk110
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
babuk110
 
Data Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory AllocationData Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory Allocation
babuk110
 
Data Structure & Algorithms - Introduction
Data Structure & Algorithms - IntroductionData Structure & Algorithms - Introduction
Data Structure & Algorithms - Introduction
babuk110
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
babuk110
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
babuk110
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
babuk110
 
Deployment Models-Internet of things Materials
Deployment Models-Internet of things MaterialsDeployment Models-Internet of things Materials
Deployment Models-Internet of things Materials
babuk110
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
babuk110
 
Data Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory AllocationData Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory Allocation
babuk110
 
Data Structure & Algorithms - Introduction
Data Structure & Algorithms - IntroductionData Structure & Algorithms - Introduction
Data Structure & Algorithms - Introduction
babuk110
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
babuk110
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
babuk110
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
babuk110
 
Ad

Recently uploaded (20)

Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
Comprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptxComprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptx
dd7devdilip
 
W1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptxW1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptx
muhhxx51
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
Compiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptxCompiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptx
RushaliDeshmukh2
 
Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdf
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdfCOMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdf
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdf
Alvas Institute of Engineering and technology, Moodabidri
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
Comprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptxComprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptx
dd7devdilip
 
W1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptxW1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptx
muhhxx51
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
Compiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptxCompiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptx
RushaliDeshmukh2
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 

Data Structure & Algorithms - Operations

  • 2. Data Structure Operations • The data in the data structures are processed by certain operations. o Traversing o Searching o Inserting o Updating o Deleting o Sorting o Merging
  • 3. Data Structure Operations (Cont..) • Traversing - Visiting each record so that items in the records can be accessed. • Searching - Finding the location of the record with a given key or value or finding all records which satisfy given conditions. • Inserting - Adding a new record to the data structure. • Updating – Change the content of some elements of the record. • Deleting - Removing records from the data structure. • Sorting - Arranging records in some logical or numerical order. o (Eg: Alphabetic order) • Merging - Combing records from two different sorted files into a single file.
  • 4. Example • An organization contains a membership file in which each record contains the following data for a given member: Name, Address, Telephone Number, Age, Sex a. Suppose the organization wants to announce a meeting through a mailing. Then one would traverse the file to obtain Name and Address of each member. b. Suppose one wants to find the names of all members living in a particular area. Again traverse and search the file to obtain the data. c. Suppose one wants to obtain Address of a specific Person. Then one would search the file for the record containing Name. d. Suppose a member dies. Then one would delete his or her record from the file.
  • 5. Example e. Suppose a new person joins the organization. Then one would insert a record into the file f. Suppose a member has shifted to a new residence his/her address and telephone number need to be changed. Given the name of the member, one would first need to search for the record in the file. Then perform the update operation, i.e. change some items in the record with the new data. g. Suppose one wants to find the number of members whose age is 65 or above. Again one would traverse the file, counting such members.
  • 7. Abstract Data Types • An Abstract Data type (ADT) is a type for objects whose behavior is defined by a set of value and a set of operations. • ADT refers to a set of data values and associated operations that are specified accurately, independent of any particular implementation. • The ADT consists of a set of definitions that allow us to use the functions while hiding the implementation. • Abstract in the context of data structures means everything except the detailed specifications or implementation. • Data type of a variable is the set of values that the variable can take. • Examples: Stacks, Queues, Linked List ADT = Type + Function Names + Behaviour of each function
  • 8. ADT Operations • While modeling the problems the necessary details are separated out from the unnecessary details. This process of modeling the problem is called abstraction. • The model defines an abstract view to the problem. It focuses only on problem related stuff and that you try to define properties of the problem. • These properties include o The data which are affected. o The operations which are identified.
  • 9. ADT Operations ( Cont..) • Abstract data type operations are o Create - Create the data structure. o Display - Displaying all the elements stored in the data structure. o Insert - Elements can be inserted at any desired position. o Delete - Desired element can be deleted from the data structure. o Modify - Any desired element can be deleted/modified from the data structure.
  • 10. Abstract Data Types Model • The ADT model has two different parts functions (public and private) and data structures. • Both are contained within the ADT model itself, and do not come within the scope of the application program. • Data structures are available to all of the ADT’s functions as required, and a function may call any other function to accomplish its task. • Data structures and functions are within the scope of each other.
  • 11. Abstract Data Types Model (Cont..) • Data are entered, accessed, modified and deleted through the external application programming interface. • For each ADT operation, there is an algorithm that performs its specific task. • The operation name and parameters are available to the application, and they provide only an interface to the application. • When a list is controlled entirely by the program, it is implemented using simple structure.
  • 12. Review Questions • ______ are used to manipulate the data contained in various data structures. • In ______, the elements of a data structure are stored sequentially. • ______ of a variable specifies the set of values that the variable can take. • Abstract means ______. • If the elements of a data structure are stored sequentially, then it is a ______.
  • 14. Algorithms • An algorithm is a well defined list of steps for solving a particular problem. • The time and space are two major measures of the efficiency of an algorithm. • The complexity of an algorithm is the function which gives the running time and / or space in terms of input size.
  • 15. Searching Algorithms • Searching Algorithms are designed to check for an element or retrieve an element from any data structure where it is stored. • Based on the type of search operation, these algorithms are generally classified into two categories: • Linear Search • Binary Search
  • 16. Linear Search • Linear search is a very basic and simple search algorithm. • In Linear search, we search an element or value in a given array by traversing the array from the starting, till the desired element or value is found or we can establish that the element is not present. • It compares the element to be searched with all the elements present in the array and when the element is matched successfully, it returns the index of the element in the array, else it return -1. • Linear search is applied on unsorted or unordered lists, when there are fewer elements in a list.
  • 17. Linear Search - Example • Search each record of the file, one at a time, until finding the given value.
  • 18. Algorithm for Linear Search • In Steps 1 and 2 of the algorithm, we initialize the value of POS and I. • In Step 3, a while loop is executed that would be executed till I is less than N. • In Step 4, a check is made to see if a match is found between the current array element and VAL. • If a match is found, then the position of the array element is printed, else the value of I is incremented to match the next element with VAL. • If all the array elements have been compared with VAL and no match is found, then it means that VAL is not present in the array.
  • 20. Linear Search - Advantages • When a key element matches the first element in the array, then linear search algorithm is best case because executing time of linear search algorithm is O(n), where n is the number of elements in an array. • The list doesn’t have to sort. Contrary to a binary search, linear searching does not demand a structured list. • Not influenced by the order of insertions and deletions. Since the linear search doesn’t call for the list to be sorted, added elements can be inserted and deleted.
  • 21. Linear Search - Disadvantages • The drawback of a linear search is the fact that it is time consuming if the size of data is huge. • Every time a vital element matches the last element from the array or an essential element does not match any element Linear search algorithm is the worst case.
  • 22. Binary Search • Binary Search is used with sorted array or list. In binary search, we follow the following steps: 1) We start by comparing the element to be searched with the element in the middle of the list/array. 2) If we get a match, we return the index of the middle element and terminate the process 3) If the element/number to be searched is greater than the middle element, we pick the elements on the left/right side of the middle element, and move to step 1. 4) If the element/number to be searched is lesser in value than the middle number, then we pick the elements on the right/left side of the middle element, and move to step 1.
  • 23. Binary Search - Example • Binary Search is useful when there are large number of elements in an array and they are sorted.
  • 24. Algorithm for Binary Search • In Step 1, we initialize the value of variables, BEG, END, and POS. • In Step 2, a while loop is executed until BEG is less than or equal to END. • In Step 3, the value of MID is calculated. • In Step 4, we check if the array value at MID is equal to VAL. If a match is found, then the value of POS is printed and the algorithm exits. If a match is not found, and if the value of A[MID] is greater than VAL, the value of END is modified, otherwise if A[MID] is greater than VAL, then the value of BEG is altered. • In Step 5, if the value of POS = –1, then VAL is not present in the array and an appropriate message is printed on the screen before the algorithm exits.
  • 26. Binary Search (Cont..) Advantages • It eliminates half of the list from further searching by using the result of each comparison. • It indicates whether the element being searched is before or after the current position in the list. • This information is used to narrow the search. • For large lists of data, it works significantly better than linear search. Disadvantages • It employs recursive approach which requires more stack space. • Programming binary search algorithm is error prone and difficult. • The interaction of binary search with memory hierarchy i.e. caching is poor.
  • 27. Difference between Linear & Binary Search Linear Search • Linear Search necessitates the input information to be not sorted • Linear Search needs equality comparisons. • Linear search has complexity C(n)= n/2. • Linear Search needs sequential access. Binary Search • Binary Search necessitates the input information to be sorted. • Binary Search necessitates an ordering contrast. • Binary Search has complexity C(n)= log 2 n. • Binary Search requires random access to this information.