You are on page 1of 30

BTCS301-18

Data Structure and


Algorithms

Dr. Dinesh Kumar


Associate Professor & Head
Department of Information Technology
DAVIET, Jalandhar

It.davietjal.org DoITDAVIET
Contents

 Basic Terminologies
 What is Data Structure?
 Classification of Data Structures
 Brief introduction to each data structure
 Operations on data structures
 Introduction to algorithms
 Algorithmic Notations with examples
 Complexity of Algorithm
 Algorithm Analysis
 Asymptotic Notations
 Algorithm Criteria's
 Time Space Trade-off
Basic Terminologies/Concepts

 Data
 Information
 Field/Attribute
 Record
 Table/File
 Database
 Data Type
 Abstract Data Type
 Algorithm
 Program
What is a Data Structure?

 Definition: A data structure is a particular way of organizing,


managing and storing data in a computer so that it can be
accessed and modified effectively.
 Study of data structure includes
 Logical or mathematical description of the data structure
 Implementation of the data structures
 Quantitative Analysis of the data structures
 When the data are stored in main memory - Data Structure
 When the data are stored in secondary memory - File Structure
Classification of Data Structures

Data Structures

Linear Non-Linear
Brief Introduction to various data
structures
Array

Linked List
Brief Introduction to various data
structures
Linked List
Brief Introduction to various data
structures
Stack

Queue
Brief Introduction to various data
structures
Tree

Graph
Operations on Data Structures

Traversing
 Traversal is a process of visiting each and every element of the
data structure at least once in systematic manner.
Operations on Data Structures

Insertion
 Add a new data item in the data structure.
Operations on Data Structures

Deletion
 Delete an existing data item from the data structure.
Operations on Data Structures

Searching
 Finding the existence of desired data item with the given key
from the list of data items or finding the locations of all data
elements that satisfy certain conditions.
Operations on Data Structures

Sorting
 Sorting is a process of arranging all data items in a data structure
in a particular order.
Operations on Data Structures

Merging
 Merging is a process of combining the data items of two
different sorted list into a single sorted list.
Additional Operations on Data
Structures
Algorithm defined

 Algorithm is a finite sequence of well-defined, computer-implementable


instructions, typically to solve a class of specific problems or to perform a
computation
 Starting from an initial state and initial input, the instructions describe
a computation that, when executed, proceeds through a finite number of
well-defined successive states, eventually producing "output“ and
terminating at a final ending state.
 There are many types of Algorithms, but the fundamental types of
algorithms are:

Recursive Divide & Conquer


Greedy Algorithm
Algorithm Algorithm

Dynamic
Backtracking Brute Force Randomized
Programming
Algorithm Algorithm Algorithm
Algorithm
Algorithmic Notations

 Each algorithm is assigned a unique name.


 The steps of the algorithm should be numbered starting from 1.
 Comments may be included in the algorithm in [ ]
 Variable names should be in capital letters
 Assignment Operator (:=)
 Input and Output statements with Read and Write
 Algorithm ends with Exit statement
 Conditional Statements (If statement)
 Single
 Double
 Multiple
Algorithmic Notations

 Looping Statement
 Repeat For Statement
 Repeat While Statement
 Sub Algorithms
 Invoked by Call Statement
 Last step is Return statement instead of Exit
Some Examples

 Sum of two numbers


Some Examples

 Sum of Array element


Some Examples

 Print largest element from an array


Algorithm Complexities

 Definition: Complexity of an algorithm is a function f(n) which


measures the amount of time and/or space required by an
algorithm for an input of a given size (n).
 Complexity measures the effectiveness of an algorithm and it is also
used to compare algorithms which solves a particular problem.
 Complexity is a rough approximation of the number of steps
necessary to execute an algorithm.
 Time Complexity: Running time of the program as a function of the size of
input
 Space Complexity: Amount of computer memory required during the
program execution, as a function of the input size
Algorithm Analysis

 Three types of analysis that we perform on a particular algorithm.

 Best Case: In which we analyze the performance of an algorithm


for the input, for which the algorithm takes less time or space.

 Worst Case: In which we analyze the performance of an


algorithm for the input, for which the algorithm takes long time or
space.

 Average Case: In which we analyze the performance of an


algorithm for the input, for which the algorithm takes time or
space that lies between best and worst case.
Asymptotic Notations

 Asymptotic notations are the mathematical notations used to


describe the running time of an algorithm when the input tends
towards a particular value or a limiting value. This is also known as
an algorithm’s growth rate.
 Types of Asymptotic Notation:
 Big-O Notation (Ο) – Big O notation specifically describes worst case
scenario. It represents the upper bound running time complexity of an
algorithm.
 Omega Notation (Ω) – Omega(Ω) notation specifically describes best
case scenario. It represents the lower bound running time complexity of
an algorithm.
 Theta Notation (θ) – This notation represents the average complexity of
an algorithm. It describes both upper bound and lower bound of an
algorithm.
Asymptotic Notations

 Rate of Growth
 Logarithmic - log n
 Linear - n
 Quadratic - n2
 Log-linear growth – n log n
 Polynomial - nz
 Exponential - an
 Factorial – n!
Rate of Growth Example
Algorithm Criteria's

 Every algorithm must satisfy the following criteria:


1) Input: There are zero or more quantities which are externally
supplied
2) Output: At least one quantity is produced.
3) Definiteness: Each instruction must be clear and unambiguous;
4) Finiteness: If we trace out the instructions of an algorithm, then
for all cases the algorithm will terminate after a finite number of
steps;
5) Effectiveness: Every instruction must be sufficiently basic that it
can in principle be carried out by a person using only pencil
and paper.
Time Space Tradeoff

 Time-space tradeoff is a way of solving a problem or calculation in


less time by using more storage space (or memory), or by solving a
problem in very little space by spending a long time.

You might also like