You are on page 1of 14

•1

Array-ADT

 Slides taken from various resources from Internet


Content Outline
•2

 ADT Array -- searching and sorting on arrays:


 Linear search, binary search on a sorted array.
 Bubble sort, Insertion sort, Selection sort, Merge
Sort and analysis;
 Emphasis on the comparison based sorting model.
Counting sort, Radix sort, bucket sort. (6 lectures)
ADT in Simple Words
•3

 Definition:
 Is a set of data and its associated operation on it
 Mathematical abstraction
 No implementation detail
 ADT is a mathematical model which defines two
things
 The type of data and
 Its associated operations defined on that data
Abstract Data Types (ADTs)
 An abstract data type (ADT) is an
abstraction of a data structure
 An ADT specifies:
 Data stored
 Operations on the data
 Error conditions associated with
operations

•4
ADT vs Data Structure
•5
ADT vs Data Structure (contd.)
•6
Array as ADT
•7

 Array is probably he most versatile or fundamental


Abstract Data type
 An array is a finite sequence of storage cells, for
which he following operations are defined.
 create(A,N)- creates an array A with storage for N
items
 A[i]=item -sores item in the ith position in the array A
 A[i] – returns the value of the item stored in the ith
position in the array A.
Array as ADT
•8

 Let A be an array and has n elements then it satisfied


the following operations
 Create(A)- create an array A
 Insert(A,x,i)- Insert an element x into an array A in ith location
 Delete(A,x)- Delete an element x from an array
 Modify(A,x,y)- modify element x by y of an array A
 Traverse(A)- access all elements of an array A
 Merge(A,B)- merging elements of A and B into a third array C
 Thus by using 1D array we can perform the above
operations thus an array act as an ADT
What is an algorithm?
An algorithm is a sequence of unambiguous instructions
for solving a problem, i.e., for obtaining a required
output for any legitimate input in a finite amount of
time.
problem

algorithm

Input/ instance “computer” output


Algorithm
 An algorithm is a sequence of unambiguous
instructions for solving a problem, i.e., for obtaining a
required output for any legitimate input in a finite
amount of time.
 Can be represented various forms
 Unambiguity/clearness
 Effectiveness
 Finiteness/termination
 Correctness

•1-10
Analysis of algorithms
 Issues:
 correctness
 time efficiency
 space efficiency
 optimality

 Approaches:
 empirical analysis
 theoretical analysis
Empirical analysis of time
efficiency
 Select a specific (typical) sample of inputs
 Analyze the empirical data
 Use physical unit of time (e.g., milliseconds) or
 Of course, we can simply use some standard unit of
time measurement—a second, or millisecond, and so
on—to measure the running time of a program
implementing the algorithm.
Empirical analysis of time efficiency-
•13
cont.
 There are obvious drawbacks to such an approach
 dependence on the speed of a particular computer
 dependence on the quality of a program implementing
the algorithm
 the compiler used in generating the machine code
 the difficulty of clocking the actual running time of the
program.
 Since we are after a measure of an algorithm’s
efficiency, we would like to have a metric that does
not depend on these extraneous factors.
Summary
 ADT
 ADT vs Data Structure
 Empirical Analysis of time efficiency

You might also like