Lecture # 1-2-Intro
Lecture # 1-2-Intro
Dr. M. Nadeem
Books
C++ Plus Data Structure by Nell Dale, 3rd Edition
Simple
Easier Processing
Operations on Data Structure
There are various operations that can be performed on
Data Structure:
√ Traversal
√ Insertion
√ Deletion
√ Searching
√ Sorting
√ Merging
Types of Data Structure
Basically Data Structure can be classified into two
categories:
array
Linear Data Structure
Stack
√ Stack is a linear Data Structure in which insertion and
deletion operation are performed at same end.
√ Examples:
√ Books on a floor
√ Dishes on a shelf
√ Operations
√ Push
√ Pop stack
Linear Data Structure
Queue
√ Queue is a linear Data Structure in which insertion
operation is performed at one end called Rear end and
deletion operation is performed at another end called
front end
Linear Data Structure
Queue
√ Insertion at the rear end
√ Deleted at the front
queue
Linear Data Structure
Link List
√ Linked list is an ordered set which consist of
variable number of elements.
√ In Linked list elements are logically adjacent
to each other but they are physically not
adjacent.
√ It means elements of linked list are not
sequentially stored in memory.
Linear Data Structure
Link List
√ Link list is a record which are linked together
√A Flexible structure, because can
grow and shrink on demand.
√ Elements can be:
Inserted
Accessed
Deleted
At any position
Linked list
Non-Linear Data Structure
"The Data Structure in which elements are
arranged such that we can not process them in
linear fashion (sequentially) is called Non-Linear
data structure.“
Non Linear Data Structures are useful to represent
more complex relationships as compared to Linear
Data Structures.
√ All the nodes in a tree except root node having only one
Predecessor.
√ Each node in a tree having 0 or more Successor.
tree
Non-Linear Data Structure
Graph
1 3
6 4
5
Complexity of Algorithm
Time Complexity
√ The amount of time needed by a program to complete
its execution is known as Time complexity
√ The measurement of time is done in terms of number of
instructions executed by the program during its
execution
√ Thus Time Complexity depends on the Size of the
program and type of the algorithm being used
Complexity of Algorithm
Space Complexity
The amount of memory needed by a program during its
execution is known as Space complexity.
Total memory space need by the program is the sum of
following two memory:
Fixed size Memory:
√ It contains the space required for simple variables, constants,
instructions and fixed size structured variable such as array.
Variable size Memory:
√ It contains the space required for structured variable to which
memory is allocated run time. It also contains space required
while function is calling itself.
Complexity of Algorithm
Best case Time Complexity
The measurement of minimum time that is required by an
algorithm to complete its execution is known as Best Case
Time Complexity.
Time complexity of particular algorithm can be calculated
by providing different input values to the algorithm.
Consider an example of sorting N elements. If we supply
input values that is already sorted, an algorithm required
less time to sort them.
This is known as Best case time complexity. However best
case time complexity does not guarantee that the
algorithm will always execute within this time for different
input values.
Complexity of Algorithm
Average case Time Complexity
The measurement of average time that is required by an
algorithm to complete its execution is known as Average
Case Time Complexity.
Time complexity of particular algorithm can be
calculated by providing different input values to the
algorithm.
Consider an example of sorting N elements. Average
time complexity can be calculated by measuring the
time required to complete the execution of an algorithm
for different input values and then calculate the average
time required to sort N elements
Complexity of Algorithm
Worst case Time Complexity
The measurement of maximum time that is required by
an algorithm to complete its execution is known as Worst
Case Time Complexity.
Time complexity of particular algorithm can be calculated
by providing different input values to the algorithm.
Consider an example of sorting N elements. If we supply
input values that is in reverse order, an algorithm
required maximum time to sort them. This is known as
worst case time complexity.
Thus, worst case time complexity always guarantees that
the algorithm will always execute within this time for
different input values.
Asymptotic Notations
Asymptotic Notations are used to describe the
complexity of an algorithm. Complexity of an
algorithm indicates how much time needed by an
algorithm to complete its execution for given set of
input data.