DS THROUGH C - UNIT-1
DS THROUGH C - UNIT-1
UNIT – I
DATA STRUCTURES
DEFINITION
A data structure is a group of data elements that are put together
under one name and which defines a particular way of storing and
organizing data in a computer so that it can be used efficiently.
or
It is the way of organizing, storing, retrieving data and maintain their
relationship with each other.
or
It is the logical and mathematical model to organize and store data
in computer memory so that we can use it efficiently.
WWW.JNTUKNOTES.COM 1
DATA STRUCTURES
WWW.JNTUKNOTES.COM 2
DATA STRUCTURES
WWW.JNTUKNOTES.COM 3
DATA STRUCTURES
Graphs
Insertion: - It is used to add new data items to the given list of data
items. For example, to add the details of a new student who has recently
joined the course.
Deletion: - It means to remove (delete) a particular data item from the
given collection of data items. For example, to delete the name of a
student who has left the course.
Searching: - It is used to find the location of one or more data items
that satisfy the given constraint. Such a data item may or may not be
present in the given collection of data items. For example, to find the
names of all the students who secured 100 marks in mathematics.
Traversing: - It means to access each data item exactly once so that it
can be processed. For example, to print the names of all the students in
a class.
WWW.JNTUKNOTES.COM 4
DATA STRUCTURES
PRELIMINARIES OF ALGORITHMS
An algorithm is defined as a finite sequence of instructions each of
which has a clear meaning and can be performed with a finite amount of
effort in a finite amount of time.
WWW.JNTUKNOTES.COM 5
DATA STRUCTURES
Structure of Algorithm
The structure contains the following steps:
Input Step
Assignment Step
WWW.JNTUKNOTES.COM 6
DATA STRUCTURES
Decision Step
Repetitive Step
Output Step
WWW.JNTUKNOTES.COM 7
DATA STRUCTURES
Properties of Algorithms
Finiteness: An algorithm must terminate after a finite number of steps.
Definiteness: The steps of the algorithm must be precisely defined or
unambiguously specified.
Generality: An algorithm must be generic enough to solve all problems
of a particular class.
Effectiveness: The operations of the algorithm must be effective such
that it must easily converted into machine code in a finite amount of
time.
Input-Output: The algorithm must have zero, one or more inputs and
one or more outputs.
Analysis of Algorithms
It is a technique to compare efficiency of different algorithms
WWW.JNTUKNOTES.COM 8
DATA STRUCTURES
WWW.JNTUKNOTES.COM 9
DATA STRUCTURES
10
WWW.JNTUKNOTES.COM 10
DATA STRUCTURES
Analyzing Algorithms
Suppose “M” is an algorithm, and suppose “n” is the size of the input
data. Clearly the complexity f(n) of M increases as n increases.
It is usually the rate of increase of f(n) with some standard functions.
The most common computing times are
11
WWW.JNTUKNOTES.COM 11
DATA STRUCTURES
O(1), O(log2 n), O(n), O(n log2 n), O(n2), O(n3), O(2n)
When we have two algorithms to perform the same task and if first one
time complexity is O(n) and second one is O(n2) then we prefer first one
since as n increases the time required for execution of second one is
taking more time than the first one.
Here we discuss about three cases for the efficiency of the algorithm.
Best case – 1
Worst case – n
Average case – (n+1)/2
It the algorithm takes minimum amount of time to run for its completion
then it is called best case time complexity
It the algorithm takes maximum amount of time to run for its
completion then it is called worst case time complexity
It the algorithm takes average amount of time to run for its completion
then it is called average case time complexity
12
WWW.JNTUKNOTES.COM 12