SlideShare a Scribd company logo
1 of 57
Topics to be discussed
 Introduction to Algorithm
 Algorithm Design
 Complexity
 Asymptotic notations
 Introduction to Data Structures
 Classification of Data structure
 Abstract Data Type (ADT)
Introduction to Algorithm
 An algorithm is a Step By Step process to solve a
problem, where each step indicates an intermediate task.
Algorithm contains finite number of steps that leads to the
solution of the problem.
Structure of an Algorithm
An algorithm has the following structure
 Input Step
 Assignment Step
 Decision Step
 Repetitive Step
 Output Step
Properties /Characteristics of
an Algorithm
Algorithm has the following basic properties
 Input-Output:- Algorithm takes ‘0’ or more input and
produces the required output. This is the basic
characteristic of an algorithm.
 Finiteness:- An algorithm must terminate in countable
number of steps.
Properties /Characteristics of
an Algorithm
 Definiteness: Each step of an algorithm must be stated
clearly and unambiguously.
 Effectiveness: Each and every step in an algorithm can be
converted in to programming language statement.
 Generality: Algorithm is generalized one. It works on all
set of inputs and provides the required output. In other
words it is not restricted to a single input value.
Categories of Algorithm
Based on the different types of steps in an Algorithm, it
can be divided into three categories, namely
 Sequence
 Selection and
 Iteration
Categories of Algorithm
Sequence: The steps described in an algorithm are performed
successively one by one without skipping any step. The sequence
of steps defined in an algorithm should be simple and easy to
understand. Each instruction of such an algorithm is executed,
because no selection procedure or conditional branching exists in
a sequence algorithm.
 Example:
 // adding two numbers
 Step 1: start
 Step 2: read a,b
 Step 3: Sum=a+b
 Step 4: write Sum
 Step 5: stop
Categories of Algorithm
Selection: The sequence type of algorithms are not
sufficient to solve the problems, which involves decision
and conditions. In order to solve the problem which involve
decision making or option selection, we go for Selection
type of algorithm. The general format of Selection type of
statement is as shown below:
 if(condition)
 Statement-1;
 else
 Statement-2;
Categories of Algorithm
Categories of Algorithm
Iteration: Iteration type algorithms are used in solving the
problems which involves repetition of statement. In this type
of algorithms, a particular number of statements are repeated
‘n’ no. of times.
 Example1:
 Step 1 : start
 Step 2 : read n
 Step 3 : repeat step 4 until n>0
 Step 4 : (a) r=n mod 10
 (b) s=s+r
 (c) n=n/10
 Step 5 : write s
 Step 6 : stop
Algorithm Design
 Precisely define the problem. Precisely specify the input
and output. Consider all cases.
 Come up with a simple plan to solve the problem at hand.
The plan is independent of a (programming) language.
The precise problem specification influences the plan.
 Turn the plan into an implementation – The problem
representation (data structure) influences the
implementation
Classification by Design Method
 Greedy Method
 Divide and Conquer
 Dynamic Programming
 Backtracking
 Branch and Bound
Classification by Design Approaches
 Top-Down Approach: In the top-down approach, a
large problem is divided into small sub-problem. and
keep repeating the process of decomposing problems
until the complex problem is solved.
 Bottom-up approach: The bottom-up approach is also
known as the reverse of top-down approaches.
In approach different, part of a complex program is
solved using a programming language and then this is
combined into a complete program.
1.Write an algorithm for roots of a Quadratic Equation?
 // Roots of a quadratic Equation
 Step 1 : start
 Step 2 : read a,b,c
 Step 3 : if (a= 0) then step 4 else step 5
 Step 4 : Write “ Given equation is a linear equation “
 Step 5 : d=(b * b) _ (4 *a *c)
 Step 6 : if ( d>0) then step 7 else step8
 Step 7 : Write “ Roots are real and Distinct”
 Step 8: if(d=0) then step 9 else step 10
 Step 9: Write “Roots are real and equal”
 Step 10: Write “ Roots are Imaginary”
 Step 11: stop
2. Write an algorithm to find the largest among three different numbers
entered by user
 Step 1: Start
 Step 2: Declare variables a,b and c.
 Step 3: Read variables a,b and c.
 Step 4: If a>b
 If a>c
 Display a is the largest number.
 Else
 Display c is the largest number.
 Else
 If b>c
 Display b is the largest number.
 Else
 Display c is the greatest number.
 Step 5: Stop
Complexity of Algorithm
 Algorithmic complexity is concerned about how fast or
slow particular algorithm performs. We define complexity
as a numerical function T(n) - time versus the input size n.
Performance Analysis an Algorithm:
 The Efficiency of an Algorithm can be measured by the
following metrics.
Time Complexity:
 The amount of time required for an algorithm to complete
its execution is its time complexity. An algorithm is said to
be efficient if it takes the minimum (reasonable) amount
of time to complete its execution.
Complexity of Algorithm
Space Complexity:
 The amount of space occupied by an algorithm is known
as Space Complexity. An algorithm is said to be efficient
if it occupies less space and required the minimum amount
of time to complete its execution.
Example
Example
The total frequency counts of the program segments A, B and C given by 1,
(3n+1) and (3n2+3n+1) respectively are expressed as O(1), O(n) and O(n2)
Asymptotic Notations
 Asymptotic notations are the mathematical notations used
to describe the running time of an algorithm when the
input tends towards a particular value or a limiting value.
 It is often used to describe how the size of the input data
affects an algorithm’s usage of computational resources.
 The time required by an algorithm falls under three types
Best Case − Minimum time required for program
execution.
 Average Case − Average time required for program
execution.
 Worst Case − Maximum time required for program
execution.
Asymptotic Notations
 The time required by an algorithm falls under three types
Best Case − Minimum time required for program
execution.
 Average Case − Average time required for program
execution.
 Worst Case − Maximum time required for program
execution.
Types of Asymptotic Notations
There are mainly three asymptotic notations:
1.Big-O Notation (O-notation)
2.Omega Notation (Ω-notation)
3.Theta Notation (Θ-notation)
Big-O Notation (O-notation)
 Big-O notation represents the upper bound of the running
time of an algorithm. It measures the worst case time
complexity or the longest amount of time an algorithm can
possibly take to complete.
Asymptotic Notations
 If f(n) describes the running time of an algorithm, f(n) is
O(g(n)) if there exist a positive constant C and positive
integer n0 such that, 0 ≤ f(n) ≤ cg(n) for all n ≥ n0
 Example: Find upper bound of running time of constant
function f(n) = 6993.
 To find the upper bound of f(n), we have to find c and
n0 such that 0 ≤ f (n) ≤ c.g(n) for all n ≥ n0
 0 ≤ f (n) ≤ c × g (n)
 0 ≤ 6993 ≤ c × g (n)
 0 ≤ 6993 ≤ 6993 x 1
 So, c = 6993 and g(n) = 1
 Any value of c which is greater than 6993, satisfies the
above inequalities, so all such values of c are possible.
 0 ≤ 6993 ≤ 8000 x 1 → true
 0 ≤ 6993 ≤ 10500 x 1 → true
 Function f(n) is constant, so it does not depend on
problem size n. So n0= 1
 f(n) = O(g(n)) = O(1) for c = 6993, n0 = 1
 f(n) = O(g(n)) = O(1) for c = 8000, n0 = 1 and so on.
 Example: Find upper bound of running time of a linear
function f(n) = 6n + 3.
 To find upper bound of f(n), we have to find c and n0 such
that 0 ≤ f (n) ≤ c × g (n) for all n ≥ n0
 0 ≤ f (n) ≤ c × g (n)
 0 ≤ 6n + 3 ≤ c × g (n)
 0 ≤ 6n + 3 ≤ 6n + 3n, for all n ≥ 1 (There can be such
infinite possibilities)
 0 ≤ 6n + 3 ≤ 9n
 So, c = 9 and g (n) = n, n0 = 1
 Tabular Approach
 0 ≤ 6n + 3 ≤ c × g (n)
 0 ≤ 6n + 3 ≤ 7 n
 Now, manually find out the proper n0, such that f (n) ≤ c.g
(n)
n f(n) = 6n + 3 c.g(n) = 7n
1 9 7
2 15 14
3 21 21
4 27 28
5 33 35
 From Table, for n ≥ 3, f (n) ≤ c × g (n) holds true. So, c =
7, g(n) = n and n0 = 3, There can be such multiple pair of
(c, n0)
 f(n) = O(g(n)) = O(n) for c = 9, n0 = 1
 f(n) = O(g(n)) = O(n) for c = 7, n0 = 3
 and so on.
Omega Notation (Ω-Notation)
 Omega notation represents the lower bound of the running
time of an algorithm. It measures the best case time
complexity or the best amount of time an algorithm can
possibly take to complete.
 If f(n) describes the running time of an algorithm, The
function f is said to be Ω(g), if there is a constant c > 0
and a natural number n0 such that c*g(n) ≤ f(n) for all n ≥
n0
Omega Notation (Ω-Notation)
Example
 Find lower bound of running time of constant
function f(n) = 23.
 To find lower bound of f(n), we have to find c and
n0 such that { 0 ≤ c × g(n) ≤ f(n) for all n ≥ n0 }
 0 ≤ c × g(n) ≤ f(n)
 0 ≤ c × g(n) ≤ 23
 0 ≤ 23.1 ≤ 23 → true
 0 ≤ 12.1 ≤ 23 → true
 0 ≤ 5.1 ≤ 23 → true
Example: Find lower bound of running time of a linear
function f(n) = 6n + 3.
 To find lower bound of f(n), we have to find c and n0 such
that 0 ≤ c.g(n) ≤ f(n) for all n ≥ n0
 0 ≤ c × g(n) ≤ f(n)
 0 ≤ c × g(n) ≤ 6n + 3
 0 ≤ 6n ≤ 6n + 3 → true, for all n ≥ n0
 0 ≤ 5n ≤ 6n + 3 → true, for all n ≥ n0
 Above both inequalities are true and there exists such
infinite inequalities. So,
 f(n) = Ω (g(n)) = Ω (n) for c = 6, n0 = 1
 f(n) = Ω (g(n)) = Ω (n) for c = 5, n0 = 1
 and so on.
Theta Notation (Θ-Notation)
 Theta notation represents the represents the upper and the
lower bound of the running time of an algorithm, it is used
for analyzing the average-case complexity of an
algorithm.
 The function f is said to be Θ(g), if there are constants c1,
c2 > 0 and a natural number n0 such that c1* g(n) ≤ f(n) ≤
c2 * g(n) for all n ≥ n0
 Theta Notation (Θ-Notation)
 Find tight bound of running time of constant function f(n)
= 23.
 To find tight bound of f(n), we have to find c1, c2 and
n0 such that, 0 ≤ c1× g(n) ≤ f(n) ≤ c2 × g(n) for all n ≥ n0
 0 ≤ c1× g(n) ≤ 23 ≤ c2 × g(n)
 0 ≤ 22 ×1 ≤ 23 ≤ 24 × 1, → true for all n ≥ 1
 0 ≤ 10 ×1 ≤ 23 ≤ 50 × 1, → true for all n ≥ 1
 Above both inequalities are true and there exists such
infinite inequalities.
 So, (c1, c2) = (22, 24) and g(n) = 1, for all n ≥ 1
 (c1, c2) = (10, 50) and g(n) = 1, for all n ≥ 1
 f(n) = Θ (g (n)) = Θ (1) for c1 = 22, c2 = 24, n0 = 1
 f(n) = Θ (g (n)) = Θ (1) for c1 = 10, c2 = 50, n0 = 1
 and so on.
 Example: Find tight bound of running time of a linear
function f(n) = 6n + 3.
 To find tight bound of f(n), we have to find c1, c2 and
n0 such that, 0 ≤ c1× g(n) ≤ f(n) ≤ c2 × g(n) for all n ≥ n0
 0 ≤ c1× g(n) ≤ 6n + 3 ≤ c2 × g(n)
 0 ≤ 5n ≤ 6n + 3 ≤ 9n, for all n ≥ 1
 Above inequality is true and there exists such infinite
inequalities.
 So, f(n) = Θ(g(n)) = Θ(n) for c1 = 5, c2 = 9, n0 = 1
Data Structure
 Data structure is a representation of data and the
operations allowed on that data.
 Data structure is a way to store and organize data in order
to facilitate the access and modifications.
 Data Structure are the method of representing of logical
relationships between individual data elements related to
the solution of a given problem.
Operations on the Data Structures
Following operations can be performed on the data
structures:
 Traversing
 Searching
 Inserting
 Deleting
 Sorting
 Merging
Operations on the Data Structures
 Traversing- It is used to access each data item exactly once so
that it can be processed.
 Searching- It is used to find out the location of the data item if
it exists in the given collection of data items.
 Inserting- It is used to add a new data item in the given
collection of data items.
 Deleting- It is used to delete an existing data item from the
given collection of data items.
 Sorting- It is used to arrange the data items in some order i.e. in
ascending or descending order in case of numerical data and in
dictionary order in case of alphanumeric data.
 Merging- It is used to combine the data items of two sorted
files into single file in the sorted form.
Application of Data Structures
The following are some of the most important areas
where data structures are used:
 Artificial intelligence
 Compiler design
 Machine learning
 Database design and management
 Blockchain
 Numerical and Statistical analysis
 Operating system development
 Image & Speech Processing
 Cryptography
Basic Data Structure
array
Linked list
tree
queue
stack
Selection of Data Structure
 The choice of particular data model depends on two
consideration:
 It must be rich enough in structure to represent the
relationship between data elements
 The structure should be simple enough that one can
effectively process the data when necessary
Types of Data Structure
 Linear: In Linear data structure, values are arrange in
linear fashion.
 Array: Fixed-size
 Linked-list: Variable-size
 Stack: Add to top and remove from top
 Queue: Add to back and remove from front
 Priority queue: Add anywhere, remove the highest
priority
Types of Data Structure
 Non-Linear: The data values in this structure are not
arranged in order.
 Hash tables: Unordered lists which use a ‘hash
function’ to insert and search
 Tree: Data is organized in branches.
 Graph: A more general branching structure, with less
strict connection conditions than for a tree
Type of Data Structures
 Homogenous: In this type of data structures, values of the
same types of data are stored.
 Array
 Non-Homogenous: In this type of data structures, data
values of different types are grouped and stored.
 Structures
 Classes
Abstract Data Type and Data
Structure
 Definition:-
 Abstract Data Types (ADTs) stores data and allow various
operations on the data to access and change it.
 A mathematical model, together with various operations
defined on the model
 An ADT is a collection of data and associated operations for
manipulating that data
 Data Structures
 Physical implementation of an ADT
 data structures used in implementations are provided in a
language (primitive or built-in) or are built from the
language constructs (user-defined)
 Each operation associated with the ADT is implemented by
one or more subroutines in the implementation
Abstract Data Type(ADT)
 ADTs support abstraction, encapsulation, and information
hiding.
 Abstraction is the structuring of a problem into well-
defined entities by defining their data and operations.
 The principle of hiding the used data structure and to only
provide a well-defined interface is known as
encapsulation.
The Core Operations of ADT
 Every Collection ADT should provide a way to:
 add an item
 remove an item
 find, retrieve, or access an item
 Many, many more possibilities
 is the collection empty
 make the collection empty
 give me a sub set of the collection
The Core Operations of ADT
• No single data structure works well for all purposes, and
so it is important to know the strengths and limitations
of several of them
Stacks
 Collection with access only to the last element inserted
 Last in first out
 insert/push
 remove/pop
 top
 make empty
Top
Data4
Data3
Data2
Data1
Queues
 Collection with access only to the item that has been
present the longest
 Last in last out or first in first out
 enqueue, dequeue, front
 priority queues and dequeue
Data4
Data3
Data2
Data1
Front Back
List
 A Flexible structure, because can grow and shrink on
demand.
Elements can be:
 Inserted
 Accessed
 Deleted
At any position
first
last
Tree
 A Tree is a collection of elements called nodes.
 One of the node is distinguished as a root, along with a
relation (“parenthood”) that places a hierarchical structure
on the nodes.
Root

More Related Content

Similar to Data_Structure_and_Algorithms_Lecture_1.ppt

Aad introduction
Aad introductionAad introduction
Aad introductionMr SMAK
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfMemMem25
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performanceHabitamuAsimare
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsMAHERMOHAMED27
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 

Similar to Data_Structure_and_Algorithms_Lecture_1.ppt (20)

3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
Aad introduction
Aad introductionAad introduction
Aad introduction
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performance
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 

Recently uploaded (20)

9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 

Data_Structure_and_Algorithms_Lecture_1.ppt

  • 1.
  • 2.
  • 3. Topics to be discussed  Introduction to Algorithm  Algorithm Design  Complexity  Asymptotic notations  Introduction to Data Structures  Classification of Data structure  Abstract Data Type (ADT)
  • 4. Introduction to Algorithm  An algorithm is a Step By Step process to solve a problem, where each step indicates an intermediate task. Algorithm contains finite number of steps that leads to the solution of the problem.
  • 5. Structure of an Algorithm An algorithm has the following structure  Input Step  Assignment Step  Decision Step  Repetitive Step  Output Step
  • 6. Properties /Characteristics of an Algorithm Algorithm has the following basic properties  Input-Output:- Algorithm takes ‘0’ or more input and produces the required output. This is the basic characteristic of an algorithm.  Finiteness:- An algorithm must terminate in countable number of steps.
  • 7. Properties /Characteristics of an Algorithm  Definiteness: Each step of an algorithm must be stated clearly and unambiguously.  Effectiveness: Each and every step in an algorithm can be converted in to programming language statement.  Generality: Algorithm is generalized one. It works on all set of inputs and provides the required output. In other words it is not restricted to a single input value.
  • 8. Categories of Algorithm Based on the different types of steps in an Algorithm, it can be divided into three categories, namely  Sequence  Selection and  Iteration
  • 9. Categories of Algorithm Sequence: The steps described in an algorithm are performed successively one by one without skipping any step. The sequence of steps defined in an algorithm should be simple and easy to understand. Each instruction of such an algorithm is executed, because no selection procedure or conditional branching exists in a sequence algorithm.  Example:  // adding two numbers  Step 1: start  Step 2: read a,b  Step 3: Sum=a+b  Step 4: write Sum  Step 5: stop
  • 10. Categories of Algorithm Selection: The sequence type of algorithms are not sufficient to solve the problems, which involves decision and conditions. In order to solve the problem which involve decision making or option selection, we go for Selection type of algorithm. The general format of Selection type of statement is as shown below:  if(condition)  Statement-1;  else  Statement-2;
  • 12. Categories of Algorithm Iteration: Iteration type algorithms are used in solving the problems which involves repetition of statement. In this type of algorithms, a particular number of statements are repeated ‘n’ no. of times.  Example1:  Step 1 : start  Step 2 : read n  Step 3 : repeat step 4 until n>0  Step 4 : (a) r=n mod 10  (b) s=s+r  (c) n=n/10  Step 5 : write s  Step 6 : stop
  • 13. Algorithm Design  Precisely define the problem. Precisely specify the input and output. Consider all cases.  Come up with a simple plan to solve the problem at hand. The plan is independent of a (programming) language. The precise problem specification influences the plan.  Turn the plan into an implementation – The problem representation (data structure) influences the implementation
  • 14. Classification by Design Method  Greedy Method  Divide and Conquer  Dynamic Programming  Backtracking  Branch and Bound
  • 15. Classification by Design Approaches  Top-Down Approach: In the top-down approach, a large problem is divided into small sub-problem. and keep repeating the process of decomposing problems until the complex problem is solved.  Bottom-up approach: The bottom-up approach is also known as the reverse of top-down approaches. In approach different, part of a complex program is solved using a programming language and then this is combined into a complete program.
  • 16. 1.Write an algorithm for roots of a Quadratic Equation?  // Roots of a quadratic Equation  Step 1 : start  Step 2 : read a,b,c  Step 3 : if (a= 0) then step 4 else step 5  Step 4 : Write “ Given equation is a linear equation “  Step 5 : d=(b * b) _ (4 *a *c)  Step 6 : if ( d>0) then step 7 else step8  Step 7 : Write “ Roots are real and Distinct”  Step 8: if(d=0) then step 9 else step 10  Step 9: Write “Roots are real and equal”  Step 10: Write “ Roots are Imaginary”  Step 11: stop
  • 17. 2. Write an algorithm to find the largest among three different numbers entered by user  Step 1: Start  Step 2: Declare variables a,b and c.  Step 3: Read variables a,b and c.  Step 4: If a>b  If a>c  Display a is the largest number.  Else  Display c is the largest number.  Else  If b>c  Display b is the largest number.  Else  Display c is the greatest number.  Step 5: Stop
  • 18. Complexity of Algorithm  Algorithmic complexity is concerned about how fast or slow particular algorithm performs. We define complexity as a numerical function T(n) - time versus the input size n. Performance Analysis an Algorithm:  The Efficiency of an Algorithm can be measured by the following metrics. Time Complexity:  The amount of time required for an algorithm to complete its execution is its time complexity. An algorithm is said to be efficient if it takes the minimum (reasonable) amount of time to complete its execution.
  • 19. Complexity of Algorithm Space Complexity:  The amount of space occupied by an algorithm is known as Space Complexity. An algorithm is said to be efficient if it occupies less space and required the minimum amount of time to complete its execution.
  • 21. Example The total frequency counts of the program segments A, B and C given by 1, (3n+1) and (3n2+3n+1) respectively are expressed as O(1), O(n) and O(n2)
  • 22. Asymptotic Notations  Asymptotic notations are the mathematical notations used to describe the running time of an algorithm when the input tends towards a particular value or a limiting value.  It is often used to describe how the size of the input data affects an algorithm’s usage of computational resources.  The time required by an algorithm falls under three types Best Case − Minimum time required for program execution.  Average Case − Average time required for program execution.  Worst Case − Maximum time required for program execution.
  • 23. Asymptotic Notations  The time required by an algorithm falls under three types Best Case − Minimum time required for program execution.  Average Case − Average time required for program execution.  Worst Case − Maximum time required for program execution.
  • 24. Types of Asymptotic Notations There are mainly three asymptotic notations: 1.Big-O Notation (O-notation) 2.Omega Notation (Ω-notation) 3.Theta Notation (Θ-notation) Big-O Notation (O-notation)  Big-O notation represents the upper bound of the running time of an algorithm. It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to complete.
  • 25. Asymptotic Notations  If f(n) describes the running time of an algorithm, f(n) is O(g(n)) if there exist a positive constant C and positive integer n0 such that, 0 ≤ f(n) ≤ cg(n) for all n ≥ n0
  • 26.  Example: Find upper bound of running time of constant function f(n) = 6993.  To find the upper bound of f(n), we have to find c and n0 such that 0 ≤ f (n) ≤ c.g(n) for all n ≥ n0  0 ≤ f (n) ≤ c × g (n)  0 ≤ 6993 ≤ c × g (n)  0 ≤ 6993 ≤ 6993 x 1  So, c = 6993 and g(n) = 1
  • 27.  Any value of c which is greater than 6993, satisfies the above inequalities, so all such values of c are possible.  0 ≤ 6993 ≤ 8000 x 1 → true  0 ≤ 6993 ≤ 10500 x 1 → true  Function f(n) is constant, so it does not depend on problem size n. So n0= 1  f(n) = O(g(n)) = O(1) for c = 6993, n0 = 1  f(n) = O(g(n)) = O(1) for c = 8000, n0 = 1 and so on.
  • 28.  Example: Find upper bound of running time of a linear function f(n) = 6n + 3.  To find upper bound of f(n), we have to find c and n0 such that 0 ≤ f (n) ≤ c × g (n) for all n ≥ n0  0 ≤ f (n) ≤ c × g (n)  0 ≤ 6n + 3 ≤ c × g (n)  0 ≤ 6n + 3 ≤ 6n + 3n, for all n ≥ 1 (There can be such infinite possibilities)  0 ≤ 6n + 3 ≤ 9n  So, c = 9 and g (n) = n, n0 = 1
  • 29.  Tabular Approach  0 ≤ 6n + 3 ≤ c × g (n)  0 ≤ 6n + 3 ≤ 7 n  Now, manually find out the proper n0, such that f (n) ≤ c.g (n) n f(n) = 6n + 3 c.g(n) = 7n 1 9 7 2 15 14 3 21 21 4 27 28 5 33 35
  • 30.  From Table, for n ≥ 3, f (n) ≤ c × g (n) holds true. So, c = 7, g(n) = n and n0 = 3, There can be such multiple pair of (c, n0)  f(n) = O(g(n)) = O(n) for c = 9, n0 = 1  f(n) = O(g(n)) = O(n) for c = 7, n0 = 3  and so on.
  • 31. Omega Notation (Ω-Notation)  Omega notation represents the lower bound of the running time of an algorithm. It measures the best case time complexity or the best amount of time an algorithm can possibly take to complete.  If f(n) describes the running time of an algorithm, The function f is said to be Ω(g), if there is a constant c > 0 and a natural number n0 such that c*g(n) ≤ f(n) for all n ≥ n0
  • 33. Example  Find lower bound of running time of constant function f(n) = 23.  To find lower bound of f(n), we have to find c and n0 such that { 0 ≤ c × g(n) ≤ f(n) for all n ≥ n0 }  0 ≤ c × g(n) ≤ f(n)  0 ≤ c × g(n) ≤ 23  0 ≤ 23.1 ≤ 23 → true  0 ≤ 12.1 ≤ 23 → true  0 ≤ 5.1 ≤ 23 → true
  • 34. Example: Find lower bound of running time of a linear function f(n) = 6n + 3.  To find lower bound of f(n), we have to find c and n0 such that 0 ≤ c.g(n) ≤ f(n) for all n ≥ n0  0 ≤ c × g(n) ≤ f(n)  0 ≤ c × g(n) ≤ 6n + 3  0 ≤ 6n ≤ 6n + 3 → true, for all n ≥ n0  0 ≤ 5n ≤ 6n + 3 → true, for all n ≥ n0  Above both inequalities are true and there exists such infinite inequalities. So,  f(n) = Ω (g(n)) = Ω (n) for c = 6, n0 = 1  f(n) = Ω (g(n)) = Ω (n) for c = 5, n0 = 1  and so on.
  • 35. Theta Notation (Θ-Notation)  Theta notation represents the represents the upper and the lower bound of the running time of an algorithm, it is used for analyzing the average-case complexity of an algorithm.  The function f is said to be Θ(g), if there are constants c1, c2 > 0 and a natural number n0 such that c1* g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n0
  • 36.  Theta Notation (Θ-Notation)
  • 37.  Find tight bound of running time of constant function f(n) = 23.  To find tight bound of f(n), we have to find c1, c2 and n0 such that, 0 ≤ c1× g(n) ≤ f(n) ≤ c2 × g(n) for all n ≥ n0  0 ≤ c1× g(n) ≤ 23 ≤ c2 × g(n)  0 ≤ 22 ×1 ≤ 23 ≤ 24 × 1, → true for all n ≥ 1  0 ≤ 10 ×1 ≤ 23 ≤ 50 × 1, → true for all n ≥ 1  Above both inequalities are true and there exists such infinite inequalities.
  • 38.  So, (c1, c2) = (22, 24) and g(n) = 1, for all n ≥ 1  (c1, c2) = (10, 50) and g(n) = 1, for all n ≥ 1  f(n) = Θ (g (n)) = Θ (1) for c1 = 22, c2 = 24, n0 = 1  f(n) = Θ (g (n)) = Θ (1) for c1 = 10, c2 = 50, n0 = 1  and so on.
  • 39.  Example: Find tight bound of running time of a linear function f(n) = 6n + 3.  To find tight bound of f(n), we have to find c1, c2 and n0 such that, 0 ≤ c1× g(n) ≤ f(n) ≤ c2 × g(n) for all n ≥ n0  0 ≤ c1× g(n) ≤ 6n + 3 ≤ c2 × g(n)  0 ≤ 5n ≤ 6n + 3 ≤ 9n, for all n ≥ 1  Above inequality is true and there exists such infinite inequalities.  So, f(n) = Θ(g(n)) = Θ(n) for c1 = 5, c2 = 9, n0 = 1
  • 40. Data Structure  Data structure is a representation of data and the operations allowed on that data.  Data structure is a way to store and organize data in order to facilitate the access and modifications.  Data Structure are the method of representing of logical relationships between individual data elements related to the solution of a given problem.
  • 41. Operations on the Data Structures Following operations can be performed on the data structures:  Traversing  Searching  Inserting  Deleting  Sorting  Merging
  • 42. Operations on the Data Structures  Traversing- It is used to access each data item exactly once so that it can be processed.  Searching- It is used to find out the location of the data item if it exists in the given collection of data items.  Inserting- It is used to add a new data item in the given collection of data items.  Deleting- It is used to delete an existing data item from the given collection of data items.  Sorting- It is used to arrange the data items in some order i.e. in ascending or descending order in case of numerical data and in dictionary order in case of alphanumeric data.  Merging- It is used to combine the data items of two sorted files into single file in the sorted form.
  • 43. Application of Data Structures The following are some of the most important areas where data structures are used:  Artificial intelligence  Compiler design  Machine learning  Database design and management  Blockchain  Numerical and Statistical analysis  Operating system development  Image & Speech Processing  Cryptography
  • 46. Selection of Data Structure  The choice of particular data model depends on two consideration:  It must be rich enough in structure to represent the relationship between data elements  The structure should be simple enough that one can effectively process the data when necessary
  • 47. Types of Data Structure  Linear: In Linear data structure, values are arrange in linear fashion.  Array: Fixed-size  Linked-list: Variable-size  Stack: Add to top and remove from top  Queue: Add to back and remove from front  Priority queue: Add anywhere, remove the highest priority
  • 48. Types of Data Structure  Non-Linear: The data values in this structure are not arranged in order.  Hash tables: Unordered lists which use a ‘hash function’ to insert and search  Tree: Data is organized in branches.  Graph: A more general branching structure, with less strict connection conditions than for a tree
  • 49. Type of Data Structures  Homogenous: In this type of data structures, values of the same types of data are stored.  Array  Non-Homogenous: In this type of data structures, data values of different types are grouped and stored.  Structures  Classes
  • 50. Abstract Data Type and Data Structure  Definition:-  Abstract Data Types (ADTs) stores data and allow various operations on the data to access and change it.  A mathematical model, together with various operations defined on the model  An ADT is a collection of data and associated operations for manipulating that data  Data Structures  Physical implementation of an ADT  data structures used in implementations are provided in a language (primitive or built-in) or are built from the language constructs (user-defined)  Each operation associated with the ADT is implemented by one or more subroutines in the implementation
  • 51. Abstract Data Type(ADT)  ADTs support abstraction, encapsulation, and information hiding.  Abstraction is the structuring of a problem into well- defined entities by defining their data and operations.  The principle of hiding the used data structure and to only provide a well-defined interface is known as encapsulation.
  • 52. The Core Operations of ADT  Every Collection ADT should provide a way to:  add an item  remove an item  find, retrieve, or access an item  Many, many more possibilities  is the collection empty  make the collection empty  give me a sub set of the collection
  • 53. The Core Operations of ADT • No single data structure works well for all purposes, and so it is important to know the strengths and limitations of several of them
  • 54. Stacks  Collection with access only to the last element inserted  Last in first out  insert/push  remove/pop  top  make empty Top Data4 Data3 Data2 Data1
  • 55. Queues  Collection with access only to the item that has been present the longest  Last in last out or first in first out  enqueue, dequeue, front  priority queues and dequeue Data4 Data3 Data2 Data1 Front Back
  • 56. List  A Flexible structure, because can grow and shrink on demand. Elements can be:  Inserted  Accessed  Deleted At any position first last
  • 57. Tree  A Tree is a collection of elements called nodes.  One of the node is distinguished as a root, along with a relation (“parenthood”) that places a hierarchical structure on the nodes. Root