Unit 1 - Data Structure - WWW - Rgpvnotes.in
Unit 1 - Data Structure - WWW - Rgpvnotes.in
Unit 1 - Data Structure - WWW - Rgpvnotes.in
Tech
Subject Name: Data Structure
Subject Code: IT-303
Semester: 3rd
Downloaded from be.rgpvnotes.in
Subject Notes
IT 302- Data Structure
Unit-1
1.1 Introduction Data
1.1.1 Data and Data Item
Data are simply collection of facts and figures. Data are values or set of values. A data item refers to a single unit
of value. Data items that are divided into sub items are group items; those that are not are called elementary
ite s. Fo e a ple, a stude t’s a e a e di ided i to th ee su ite s – [first name, middle name and last
name] but the ID of a student would normally be treated as a single item.
In the above example ( ID, Age, Gender, First, Middle, Last, Street, Area ) are elementary data items, whereas
(Name, Address ) are group data items.
Integers
supported by machine directly.
1.4.3 Linear Data Structures:- In linear data structures, elements are arranged in linear fashion. The linear
ordering is maintained either through consecutive memory locations or by means of pointers .Arrays, linked lists,
stacks and queues are examples of linear data structures in which values are stored in a sequence. Eg: Stacks ,
Queues, Lists, Arrays.
There are basically two ways of representing such linear structure in memory.
a) One way is to have the linear relationships between the elements represented by means of sequential memory
location. These linear structures are called arrays.
b) The other way is to have the linear relationship between the elements represented by means of pointers or
links. These linear structures are called linked lists.
The common examples of linear data structure are arrays, queues, stacks and linked lists.
Array: Array is a collection of data of same data type stored in consecutive memory location and is referred by
common name.
Linked list: Linked list is a collection of data of same data type but the data items need not be stored in
consecutive memory locations.
Stack: A stack is a Last-In-First-Out linear data structure in which insertion and deletion takes place at only one
end called the top of the stack.
Queue: A Queue is a First in First-Out Linear data structure in which insertions takes place one end called the rear
and the deletions takes place at one end called the Front.
1.4.4 Non-linear Data Structure:- Elements are stored based on the hierarchical relationship among the data. The
data values in this structure are not arranged in order. Tree, graph, table and sets are examples of non-linear data
structures.
The following are some of the Non-Linear data structure:
Trees: Trees are used to represent data that has some hierarchical relationship among the data elements.
Graph: Graph is used to represent data that has relationship between pair of elements not necessarily
hierarchical in nature. For example electrical and communication networks, airline routes, flow chart, graphs for
planning projects
Primitive Non-Primitive
integer
Character Linear Non-Linear
float
double Array Tree
Graph
Stack
Queue
Linked List
The data structures can also be classified on the basis of the following characteristics:
Characteristic Description
In Linear data structures,the data items are arranged in a linear sequence.
Linear
Example: Array
In Non-Linear data structures,the data items are not in sequence. Example:
Non-Linear
Tree, Graph
In homogeneous data structures,all the elements are of same type. Example:
Homogeneous
Array
In Non-Homogeneous data structure, the elements may or may not be of the
Non-Homogeneous
same type. Example: Structures
Static data structures are those whose sizes and structures associated memory
Static
locations are fixed, at compile time. Example: Array
Dynamic structures are those which expands or shrinks depending upon the
Dynamic program need and its execution. Also, their associated memory locations
changes. Example: Linked List created using pointers
Algorithm
A well-defined computational procedure that takes some value, or a set of values, as input and produces some
value, or a set of values, as output. It can also be defined as sequence of computational steps that transform
the input into the output.
Worst case efficiency: It is the maximum number of steps that an algorithm can take for any collection of
data values.
Best case efficiency: It is the minimum number of steps that an algorithm can take any collection of data
values.
Average case efficiency: It can be defined as the efficiency averaged on all possible inputs.
The complexity of an algorithm describes the efficiency of the algorithm in terms of the amount of the memory
required to process the data and the processing time.
Complexity of an algorithm is analyzed in two perspectives: Time and Space.
Definition:A function f(n) is said to be in O(g(n)), denoted f(n) ∈ O(g(n)), if f(n) is bounded above by some constant
multiple of g(n) for all large n, i.e., if there exist some positive constant c and some nonnegative integer n0 such
that f g fo all
For example, for a function f Ο f(n)) = { g(n) : there exists c > 0 and n0 such that g .f(n) for all n > n0. }
The Ω is the fo al a to e p ess the lo e ou d of a algo ith 's u i g ti e. It easu es the est ase
time complexity or best amount of time an algorithm can possibly take to complete.
For example, for a function f Ωf { g(n) : there exists c > 0 and n0 such that g .f(n) for all n > n0. }
The θ is the formal way to express both the lower bound and upper bound of an algorithm's running time.