DS E-Content - Module 1 Introduction
DS E-Content - Module 1 Introduction
Dr. A K Yadav
Contents
Introduction 3
Classification/Types of Data Structures 7
Applications of Data Structures 9
Algorithm 10
Efficiency of an algorithm 12
Time-space trade-off and complexity 13
Asymptotic notations 17
Complexity Analysis 21
Basic Terminology
What is Data Structure?
- A data structure is a particular way of organising data in a
computer so that it can be used effectively. The idea is to reduce
the space and time complexities of different tasks.
- The choice of a good data structure makes it possible to perform
a variety of critical operations effectively.
- An efficient data structure also uses minimum memory space and
execution time to process the structure.
- A data structure is not only used for organising the data. It is
also used for processing, retrieving, and storing data.
I Data: Data are simply values or sets of values.
I Data items: Data items refers to a single unit of values.
I Group items: Data items that are divided into sub-items are
called Group items. Ex: An Employee Name may be divided
into three subitems- first name, middle name, and last name.
I Elementary items: Data items that are not able to divide
into sub-items are called Elementary items. Ex: EnRollNo.
I Entity: An entity is something that has certain attributes or
properties which may be assigned values. The values may be
either numeric or non-numeric.
I Entities with similar attributes form an entity set.
I Each attribute of an entity set has a range of values, the set
of all possible values that could be assigned to the particular
attribute.
I The term information is sometimes used for data with given
attributes, in other words meaningful or processed data.
Algorithm
I What is an algorithm?
- An algorithm is a set of rules for carrying out calculation
either by hand or on a machine.
- An algorithm is a sequence of computational steps that
transform the input into output.
- An algorithm is a sequence of operations performed on data
that have to be organized in data structures.
- A finite set of instructions that specify a sequence of
operations to be carried out in order to solve a specific
problem or class of problems.
- An algorithm is an abstraction of a program to be executed
on a physical machine.
Efficiency of an algorithm
I To go from city “A” to city “B”, there can be many ways of
accomplishing this: by flight, by bus, by train and also by
bicycle.
I Depending on the availability, convenience, and affordability
etc., we choose the one that suits us.
I Similarly, in computer science, multiple algorithms are
available for solving the same problem (for example, a sorting
problem has many algorithms, like insertion sort, selection
sort, quick sort and many more).
I Algorithm analysis helps us to determine which algorithm is
most efficient in terms of time and space consumed.
I The goal of the analysis of algorithms is to compare algorithms
(or solutions) mainly in terms of running time but also in
terms of other factors e.g., memory, developer effort, etc.
Dr. A K Yadav Data Structures using JAVA 12/27
School of Computer Science and Engineering
Asymptotic notations
1. O - notation ”Big O” : Asymptotic upper bound,
O(g(n)) = {f (n) : ∃c, n0 > 0 such that 0 ≤ f (n) ≤
cg(n) for all n ≥ n0 }
f (n) ∈ O(g(n))
f (n) = O(g(n))
Complexity analysis
Analyzing an algorithm means predicting the resources that the
algorithm requires. Resources may be memory, communication
bandwidth, computer hardware or CPU time. Our primary concern
is to measures the computational time required for the algorithm.
Running time:-The running time of an algorithm is the number of
primitive operations or steps executed on a particular input.
Why do we normally concentrate on finding only the worst-case
running time?
1. The worst-case running time of an algorithm gives us an
upper bound on the running time for any input. So it
guarantees that the algorithm will never slower than this. In
real applications, worst case normally occurs for example
searching a non existing data.
n
X n
X n
X
⇒ T (n) = an + b + c4 tj + c5 (tj − 1) + c6 (tj − 1)
j=2 j=2 j=2
T (n) = an + b = O(n)
2. Worst Case: The algorithm performs worst if key > A[i] for
each value of j and stops only when i < 1 in step 4.
Then it will execute always j times for each value of
j = 2, 3, . . . , n
so
n
X (n − 1)(2 + n)
j=
j=2
2
Thank you
Please send your feedback or any queries to
[email protected]