2. The end of this session, You will be able to,
Explain what is Data Structure(DS) and important of
DS.
Define the Primitives operation on DS.
Differentiate the classification of DS.
Explain the Time Complexity of an algorithm.
Calculate the Time Complexity of a given algorithm.
2
3. A computer is a programmable data processor that accepts
input and instructions to process the input (program) and
generates the required output.
3
5. Data are values or a set of values
Data item refers to single unit of values
Group item :
Data item that can be subdivided into sub item.
Ex Name : First Name, Middle initial and Last
Name
Elementary item:
Data item that can not be sub divided into sub item
Ex :NI card number / Bank Pass Book Number
is treated as single item
5
6. Collection of data are frequently
organized into a hierarchy of fields,
records and files
6
7. Entity : Something that has certain attributes or
properties which may be assigned values, values may be
numeric or non-numeric.
Ex: The employee of an organization
Attributes Values
Name John
Age 33
Sex M
Employee Code 13472
7
8. Entity with similar attributes ( e.g all employees of an
organization) form an entity set.
Each attribute of an entity set has a range of values [ the
set of possible values that could be assigned to the
particular attribute].
Information: Data with given attribute or processed data.
8
9. Field is a single elementary unit of
information representing an attribute of an entity.
Record is the collection of field values of a
given entity.
File is the collection of records of the entities in
a given entity set.
9
10. Name Age Sex Roll Number Branch
A 17 M 109cs0132 CSE
B 18 M 109ee1234 EE
C 19 F 109ce0012 CE
D 20 F 108mm0132 MM
10
11. Data type refers to the kind of data a variable may store.
Whenever we try to implement any algorithm in some
programming language, we need variables.
A variable may have any value as per the facilities
provided by that language.
int, float, char, double, long double, etc.
Data type is a term that specifies the type of data that a
variable may hold in the programming language. 11
12. In general, languages have their built-in data types.
However, they also allow the user to define his or her own
data types, called user-defined data types, using the built-
in data types; for example, in the C/C++ languages, int,
float, and char are built-in data types.
Using these built-in data types, we can design (define) our
own data types by means of structures, unions, and
classes.
12
13. Data structure is a specialized format for organizing,
processing, retrieving and storing data.
The logical or mathematical model of a
particular organization of data.
The term data structure refers to the organization of data
elements and the interrelationships among them.
13
14. A data structure is a set of domains D, a designated
domain d ( D), a set of functions F, and a set of axioms A.
The triple structure (D, F, A) denotes the data structure
with the following elements:
Domain (D) This is the range of values that the data may have.
Functions (F) This is the set of operations for the data. We must
specify a set of operations for a data structure to operate on.
Axioms (A) This is a set of rules with which the different
operations belonging to F can actually be implemented. 14
15. Abstraction allows us to organize the complexity of a task
by focusing on logical properties of data and actions rather
than on the implementation details.
Logical properties refer to the ‘what’ and implementation
details refer to the ‘how’. The abstraction is at the
procedural and data level.
Data abstraction is the separation of logical properties of
the data from details of how the data is represented.
Procedural abstraction means separation of the logical
properties of action from implementation.
15
16. We defined a data structure as a way of organizing data
that specifies
1. a set of data elements, that is, a data object.
2. a set of operations that are applied to this data object.
These two sets form a mathematical construct that may be
implemented using a particular programming language.
16
17. Data appearing in DS are processed by means
of certain operation.
Particular DS one chooses for a given
situation depends largely on the frequency with
which specific operations are performed.
17
18. Traversing: Accessing each record exactly once
so that certain items in the record may be
processed [ Also known as Visiting the record].
Searching: Finding the location of the record
with a given key value, or finding the locations of
all record which satisfy one or more conditions.
18
19. Inserting : Adding a new record to the structure.
Deleting : Removing a record from the structure
19
22. The success of a software project often
depends upon the choices made in the
representation of the data and the choice of
algorithms, and hence we need better
methods to describe and process the data.
22
23. • Time complexity of an algorithm signifies the
total time required by the program to run till
its completion.
• The time complexity of algorithms is most
commonly expressed using the big O
notation.
23
24. • Time Complexity is most commonly estimated by
counting the number of elementary functions performed
by the algorithm.
• And since the algorithm's performance may vary with
different types of input data, hence for an algorithm we
usually use the worst-case Time complexity of an
algorithm because that is the maximum time taken for
any input size.
24
25. Using the RAM model of computation, we can
count how many steps our algorithm will take on
any given input instance by simply executing it on
the given input.
However, to really understand how good or bad an
algorithm is, we must know how it works
over all instances.
25
26. The worst-case complexity of the algorithm is the function
defined by the maximum number of steps taken on any
instance of size n. It represents the curve passing through
the highest point of each column.
The best-case complexity of the algorithm is the function
defined by the minimum number of steps taken on any
instance of size n. It represents the curve passing through
the lowest point of each column.
Finally, the average-case complexity of the algorithm is
the function defined by the average number of steps taken
on any instance of size n. 26
28. statement;
• Above we have a single statement. Its Time
Complexity will be Constant. The running time
of the statement will not change in relation to N.
28
29. Consider the following function:
System.out.println(number);
if(day = 1){
System.out.println(“Monday”);
}
.
.
10 million lines of code
}
Time complexity = 10 million time constant
= O(1)
29
30. for(i=0; i < N; i++)
{
statement;
}
The time complexity for the above algorithm will be
Linear. The running time of the loop is directly
proportional to N. When N doubles, so does the running
time.
30
32. MATRIX, N-BY-1
VECTOR, MULTIPLY
Y = zeros(N,1);
for i=1:N
Y(i) = 0.0;
for j=1:N
Y(i) = Y(i) + A(i,j)*x(j);
end
end
initialize space, c1N
initialize “for” loop, c2N
Scalar assignment, c3
initialize “for” loop, c2N
(3 accesses, 1 add, 1 multiply)
c4
End of loop, return/exit, c5
End of loop, return/exit, c5
Total = c1N+c2N+N(c3+c2N+N(c4+c5)+c5)
= (c2+c4+c5)N2 + (c1+c2+c3+c5)N
= c6N2 + c7N
N
times
N
times
Time complexity of an algorithm[O(N2)]
32