Introduction To Data Structures
Introduction To Data Structures
Linear Non-Linear
Elements form Sequence Elements do not form Sequence
Arrays
Linked- Lists Trees
Stacks Graphs
Queues
Types of Data Structures
Arrays:
The simplest type of Data Structures is a
linear array. By linear array we mean a list of
finite number n of similar data elements,
usually 1,2,3,4,…….,n
Linked Lists:
Linked List is a collection of nodes. Each
node is divided into two parts. First part
contains the info of the data item and the
second part contains the pointer to the next
node
Types of Data Structures
Stacks:
A Stack, also called Last-In-First-Out(LIFO)
system, is a linear list in which insertions and
deletions can take place only at one end
“top”
Queues:
A Queue, also called First-In-First-
Out(FIFO) system, is a linear list in which
deletions can take place only at one end
“front” and insertions can take place at the
other end “rear”
Types of Data Structures
Trees:
Trees are non-linear data structure used to
represent the data containing a hierarchical
relationship between elements, e.g., records,
family trees, and tables of contents
Graphs:
A Graph is a non-linear data structure having
a set V of elements called nodes and set E of
edges such that each edge e is identified with
a unique pair [u,v] of nodes in V, denoted by
e=[u,v]
Operations on data structures
Operations on Data Structures
The Data appearing in our Data Structures
are processed by means of certain operations
Traversing:
Accessing each record exactly once so that
certain items in the record may be processed
Inserting:
Adding a new record to the Structure
Deleting:
Removing a record from the Structure
Operations on Data Structures
Sorting:
Arranging the records in some logical order
Searching:
Finding the location of the record with a
given key value, or finding the locations of
all records which satisfy one or more
conditions
Merging:
Combining the records in two different
sorted files into a single sorted file
Mathematical notations
and functions
Mathematical Notations &
Functions
Floor and Ceiling Functions:
Let x be any real number. Then x lies b/w two integers called
the floor and ceiling of x.
Remainder Function:
5 ms worst-case
4 ms
3 ms
}
average-case?
best-case
2 ms
1 ms
A B C D E F G
Input
Big o notation
BIG O NOTATION
Definition:-
Suppose functions f(n) and g(n) are
functions defined on positive integer
number n, then function f(n) = O(g(n)), read
as “ f of n is big O of g of n” , or as “f(n) is
of the order of g(n)”, if there exists positive
constants c and no, such that f(n) <= c* g(n)
for all values of n>=no
Big O Notation
Big O Notation is used to measure the performance of
any algorithm. Performance of any algorithm depends
on input of any data. It is proportional to the input
data. For a particular input size n we know how a
particular algorithm behaves but when n increases and
it becomes larger, then the same algorithm behaves
differently. So O notation defines the order of
growth of any algorithm which is useful to
measure the performance of algorithm.
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) that we want
Big O Notation
to examine. This is usually done by comparing
f(n) with some standard function such as
log2n, n, n log2n, n², n3, 2n
The rates of growth of these functions are as:
log2n n n log 2n n² n3 2n
5 3 5 15 25 125 32