Data Types & Abstract Data Type
Data Types & Abstract Data Type
RAJYALAKSHMI UMMADISETTI
SENIOR LECTURER IN CME
DATA TYPES
14/08/2024
It
is the kind of data which tells the
compiler (or interpreter) how the
programmer intends to use the data.
Whereas the
underlying implementation of the
string composite type is typically
implemented using an array data
structure. 3
The ADT is special kind
of datatype, whose
behavior is defined by a
14/08/2024
set of values and set of
operations.
14/08/2024
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.
14/08/2024
ABSTRA Items stored in a stack can only be added and
removed in certain order – the last item added is the
first item removed. We call these operations, pushing
CT DATA
and popping. In this definition, we haven‘t specified
have items are stored on the stack, or how the items
are pushed and popped. We have only specified the
TYPES-
valid operations that can be performed.
EXAMPL Stack −
14/08/2024
ABSTRA
CT DATA
TYPES- Queue −
ES
not
• isEmpty(), This is used to check whether queue is
empty or not
• insert(x), This is used to add x into the queue at the
rear end
• delete(), This is used to delete one element from the 7
front end of the queue
• size(), this function is used to get number of
List −
size(), this function is used to
get number of elements present
into the list
Abstract insert(x), this function is used to
insert one element into the list
Data remove(x), this function is used
14/08/2024
ALGORITHM- CHARACTERISTICS
An algorithm is a finite sequence of instructions, each of which has a clear meaning and can
14/08/2024
be performed with a finite amount of effort in a finite length of time. No matter what the
input values may be, an algorithm terminates after executing a finite number of
instructions.
In addition every algorithm must satisfy the following criteria:
Input: there are zero or more quantities, which are externally supplied;
Finiteness: if we trace out the instructions of an algorithm, then for all cases the algorithm
will terminate after a finite number of steps;
Effectiveness: every instruction must be sufficiently basic that it can in principle be carried
9
out by a person using only pencil and paper. It is not enough that each operation be definite,
but it must also be feasible.
Analys Analysing an algorithm means calculating
is the resources required for the algorithm.
ALGORITH memory,
Resource
M s
communication bandwidth,
computation time etc.,
ANALYSIS
Desig
1. Try to save time (Time complexity).
n 2. Try to save space (Space complexity).
Goals
14/08/2024 10
TIME COMPLEXITY
14/08/2024
Time Complexity: The time needed by an
algorithm expressed as a function of the
size of a problem.
The time complexity of a program is the
amount of computer time it needs to run to
completion.
The limiting behavior of the complexity as
size increases is called the asymptotic time
complexity.
It is the asymptotic complexity of an
algorithm, which ultimately determines the
size of problems that can be solved by the
algorithm.
11
ANALYSIS OF ALGORITHMS
14/08/2024
A complete analysis of the running time of an algorithm involves
the following steps:
Implement the algorithm completely.
14/08/2024
The reason for analyzing an algorithm is to discover its
characteristics in order to evaluate its suitability for various
applications or compare it with other algorithms for the same
application.
Moreover, the analysis of an algorithm can help us understand it
14
ALGORITHM ANALYSIS
Algorithm analysis can be performed at two different stages, before
implementation and after implementation, as
1) Priori analysis: The resource(such as memory & space) requirements
are obtained by formulating a function based on theory.
It is defined as theoretical analysis of an algorithm. i.e., independent of
14/08/2024 15
PRIORI ANALYSIS
14/08/2024
In theoretical analysis of algorithms it is common to estimate
their complexity in the asymptotic sense, i.e., to estimate the
complexity function for arbitrarily large input. Big O notation, Big-
omega notation and Big-theta notation are used to this end.
Rule of thumb: Simple programs can be analyzed by counting
the nested loops of the program. A single loop over n items yields
f( n ) = n. A loop within a loop yields f( n ) = n2. A loop within a
loop within a loop yields f( n ) = n3.
Rule of thumb: Given a series of for loops that are sequential,
14/08/2024
Our algorithm is o( something ) A number is < something
Our algorithm is O( something ) A number is ≤ something
Our algorithm is Θ( something ) A number is = something
Our algorithm is Ω( something ) A number is ≥ something
Our algorithm is ω( something ) A number is > something
17
POSTERIORI ANALYSIS
structure.
The chosen algorithm is implemented using programming language.
In this analysis, actual statistics like running time and space needed are
collected.
14/08/2024 18
POSTERIORI ANALYSIS
14/08/2024
Run-time analysis Orders of growth
Run-time analysis is a theoretical classification that estimates
19
ANALYSIS TYPES
The algorithm complexity can be best, average or worst case analysis. The
14/08/2024
algorithm analysis can be expressed using Big O notation. Best, worst, and
average cases of a given algorithm express what the resource usage is at
least, at most and on average, respectively. The big o notation simplifies the
comparison of algorithms.
Best Case : Best case performance used in computer science to describe an
algorithm’s behavior under optimal conditions. An example of best case
performance would be trying to sort a list that is already sorted using some
sorting algorithm. E.G. [1,2,3] --> [1,2,3]
Average Case: Average case performance measured using the average
optimal conditions to solve the problem. For example a list that is neither best
case nor, worst case order that you want to be sorted in a certain order. E.G.
[2,1,5,3] --> [1,2,3,5] OR [ 2,1,5,3] --> [5,3,2,1]
Worst Case: Worst case performance used to analyze the algorithm's
behavior under worst case input and least possible to solve the problem. It
determines when the algorithm will perform worst for the given inputs. An 20
14/08/2024
Algorithms efficiency described in terms of Time and Space.
The time efficiency calculated using CPU utilization.
The Space efficiency calculated using memory and disk usage of an
algorithm.
The developer should know the difference between
Performance and complexity.
The complexity analysis does not depend on any computer
21
COMPLEXITY OF ALGORITHMS
14/08/2024
The complexity of an algorithm M is the function f(n) which
gives the running time and/or storage space requirement of
the algorithm in terms of the size ‗n‘ of the input data.
Mostly, the storage space required by an algorithm is simply
a multiple of the data size ‗n‘. Complexity shall refer to the
running time of the algorithm.
The function f(n), gives the running time of an algorithm,
depends not only on the size ‗n‘ of the input data but also on
the particular data. The complexity function f(n) for certain
cases are: 1. Best Case : The minimum possible value of f(n)
is called the best case. 2. Average Case : The expected value
of f(n). 3. Worst Case : The maximum value of f(n) for any key 22
possible input