SlideShare a Scribd company logo
Introduction to Data Structure
& Algorithms
Akhil Kaushik
Asstt. Prof., CE Deptt.,
TIT Bhiwani
Good Computer Program
• A computer program is a series of instructions to carry out a
particular task written in a language that a computer can
understand.
• There are a number of features for a good program:-
– Run efficiently and correctly
– Have a user friendly interface
– Be easy to read and understand
– Be easy to debug
– Be easy to modify
– Be easy to maintain
Good Computer Program
• Programs consists of two things: Algorithms and
data structures.
• A good program is a combination of both
algorithm and a data structure.
• An algorithm is a step by step recipe for solving
an instance of a problem.
What are Data Structures?
• Data structures defines a way of organizing all
data items that consider not only the elements
stored but also stores the relationship
between the elements.
• A data structure represents the logical
relationship that exists between individual
elements of data to carry out certain tasks.
What are Data Structures?
• In simple language, Data Structures are
structures programmed to store ordered data,
so that various operations can be performed
on it easily.
• Ex: Store runs according to a Batsman’s
name.
Why study Data Structures?
• To identify and develop useful mathematical
entities and operations and to determine what
class of problem can be solved by them.
• To determine representation of abstract
entities and to implement the abstract
operations on these representations
Data Type vs Data Structure
• Data type: data type a set of values that
variable may assume. Int, float, char, double,
Boolean.
• Data Structure: extension of data type i.e.
the implementation of organized data and
operations allowed on data type.
Why study Data Structures?
• DS are used in almost every program or
software.
• DS study is mandatory to develop better
algorithm.
• DS allow management of large database and
internet indexing services.
Why study Data Structures?
Study of DS includes:-
• Logical description of DS
• Implementation of DS
• Quantitative analysis of DS
Why study Data Structures?
Applications of DS are in every are including:-
• DBMS
• SIMULATION
• GRAPHICS
• NETWORK ANALYSIS
• NUMERICAL ANALYSIS
• COMPILER DESIGN
• OPERATING SYSTEM
• ARTIFICAL INTELLIGENCE
Data Structure Classification
Classification can be done on the basis of :-
1. According to nature of size
2. According to its occurrence
3. Primitive and non-primitive
Data Structure Classification
STATIC AND DYNAMIC
1. Static: Here we can store data up to a fixed no.
only.
Ex: array.
2. Dynamic: It allows programmer to change its
size during program execution to add or delete
data.
Ex: linked list, tree, etc.
LINEAR AND NON-LINEAR
1. Linear: Here data is stored in consecutive
memory allocation i.e. - sequentially.
Ex: array, linked list, queue, etc.
2. Non-linear: Here data is in no sequential form and
usually used to identify hierarchical relationship.
Ex: Trees
PRIMITIVE AND NON-PRIMITIVE
PRIMITIVE DATATYPE: These data
types are used to represent single
values.
• Integer: This is used to represent
a number without decimal point.
Ex: 12, 90
• Float and Double: This is used to
represent a number with decimal
point. Ex: 45.1, 67.3
• Character : This is used to
represent single character
Ex: ‘C’, ‘a’
• String: This is used to represent
group of characters.
Ex: “Stephen College"
NON-PRIMITIVE DATATYPES:
The data types that are derived
from primary data types are
known as non-Primitive data
types.
• These data types are used to
store group of values.
• The non-primitive data types
are
– Arrays
– Structure
– Union
– linked list
– Stacks
Homogenous vs Hetrogenous
• Homogenous: DS refer to the data structure
which store same type of elements.
Ex: arrays
• Non-homogenous: DS refer to the data
structure which store data of different type of
elements.
Ex: structure.
Operations on Data Structure
1. Traversing: Accessing each records exactly once so that
certain items in the record may be processed.
2. Searching: Finding the location of a particular record with a
given key value, or finding the location of all records which
satisfy one or more conditions.
3. Inserting: Adding a new record to the structure.
4. Deleting: Removing the record from the structure.
5. Sorting: Managing the data or record in some logical
order(Ascending or descending order).
6. Merging: Combining the record in two different sorted files into
a single sorted file.
7. Create, delete, update, etc.
Algorithms
• An algorithm is a step by step recipe for solving
an instance of a problem.
• An algorithm is a precise procedure for solving a
problem in finite number of steps.
• An algorithm states the actions to be executed
and the order in which these actions are to be
executed.
Algorithms
• An algorithm possesses the following properties:-
– It must be correct.
– It must be composed of a finite number of steps.
– There can be no ambiguity as to which step will be done next.
– It must terminate.
– It takes zero or more inputs
– It should be efficient and flexible
– It should use less memory space as much as possible
– It results in one or more outputs
Various steps in developing
Algorithms
• Devising the Algorithm:- Each step of an algorithm
must be precisely defined and no vague
statements should be used.
– Pseudo code is used to describe the algorithm, in less
formal language than a Programming language
Various steps in developing
Algorithms
• Validating the Algorithm: The proof of correctness
of the algorithm.
– A human must be able to perform each step by giving
the required input, use the algorithm and get the
required output in a finite amount of time.
• Expressing the algorithm: To implement the
algorithm in a programming language.
– The algorithm used should terminate after a finite
number of steps.
Efficiency of an Algorithm
An algorithm should meet three things:-
• It should be independent of the programming
language in which the idea is realized
• Every programmer having enough knowledge
and experience should understand it
• It should be applicable to inputs of all sizes
Efficiency of an Algorithm
• Efficiency of an algorithm denotes the rate at
which an algorithm solves a problem of size ‘n’.
• It is measured by the amount of resources it uses,
the time and the space.
• An algorithm’s complexity is measured by
calculating the time taken and space required for
performing the algorithm.
Space Complexity of an Algorithm
• It is the way in which the amount of storage space
required by an algorithm varies with the size of the
problem to be solved.
• The space occupied by the program is generally by the
following:-
– A fixed amount of memory for the program code.
– A variable amount of memory for variable. This space increases
or decreases depending upon whether the program uses
iterative or recursive procedures.
Space Complexity of an Algorithm
• Instruction Space is the space occupied by the
compiled version of the program.
• Data Space is the space used to hold the
variables , data structures, allocated memory and
other data elements.
• Environment Space is the space used on the run
time stack for each function call.
Time Complexity of an Algorithm
• The way in which the number of steps required by
an algo varies with the size of the problem it is
solving.
Time Complexity of an Algorithm
• It is the amount of time needed by a program
to complete its task.
• The time taken for an algorithm is comprised
of two times:-
– Compilation Time
– Run Time
Time Complexity of an Algorithm
• Compilation time is the time taken to compile an
algorithm.
• While compiling it checks for the syntax and
semantic errors in the program and links it with
the standard libraries, your program has asked to.
• It comes under the domain of computer science
(software dependent).
Time Complexity of an Algorithm
• Runtime is the time to execute the compiled
program.
• Note that run time is calculated only for
executable statements and not for declaration
statements.
• It comes under the domain of electronics
(depends on hardware).
Time Complexity of an Algorithm
• It can be defined for computation of function f() as
a total number of statements that are executed for
computing the value of f(n).
• Time complexity of an algorithm is generally
classified as three types:-
(i) Worst case
(ii) Average Case
(iii) Best Case
Time Complexity of an Algorithm
• Worst Case: It is the longest time that an algorithm will
use over all instances of size ‘n’ for a given problem to
produce a desired result.
– Denoted by Big-Oh (O)
• Average Case: It is the average time(or average space).
– Denoted by theta (Θ).
• Best Case: It is the shortest time (or least space).
– Denoted by Omega(Ω).
Time Complexity of an Algorithm
Time Complexity of an Algorithm
fact ( long n)
{
for (i=1; i<=n; i++)
x=i*x;
return x;
}
• Data Space: i, n and x
• Environment Space: Almost nothing
because the function is called only once.
• The algorithm has a complexity of O(1)
because it does not depend on n.
• No matter how big the problem
becomes, the space complexity remains
the same since the same variables are
used, and the function is called only
once.
Time Complexity of an Algorithm
long fact (long x)
{
if (x<=1)
return(1);
else
return (x * fact(x-1));
}
• Data space : x
• Environment Space: fact() is
called recursively , and so the
amount of space this program
used is based on the size of
the problem.
Measure Algorithms’ Performance
• It needs programs to create ,append, update the
database, print data, permit online enquiry and so
on.
• A Programmer should identify all requirements to
solve the problem like:-
– Type of Programming language
– Narration of the program describing the tasks to be
performed
– Frequency of Processing (hourly, daily, weekly etc)
– Input and output of the program
– Limitations and restrictions for the program
Measure Algorithms’ Performance
• What metric should be used to judge algorithms?
– Length of the program (lines of code)
– Ease of programming (bugs, maintenance)
– Memory required
– Running time
*Running time is the dominant standard.
– Quantifiable and easy to compare
– Often the critical bottleneck
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
Thank You !!!

More Related Content

What's hot (20)

PPT
C++ Arrays
أحمد محمد
 
PPT
Abstract data types (adt) intro to data structure part 2
Self-Employed
 
PPTX
Stack using Linked List
Sayantan Sur
 
PDF
Applications of stack
eShikshak
 
PPT
Queue in Data Structure
Muhazzab Chouhadry
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
PPTX
Tree in data structure
ghhgj jhgh
 
PPT
Queue
Nabeel Ahsen
 
PPTX
Sorting algorithms
Maher Alshammari
 
PPTX
stack & queue
manju rani
 
PPTX
Circular link list.ppt
Tirthika Bandi
 
PDF
Stack
Zaid Shabbir
 
PPTX
Binary Tree in Data Structure
Meghaj Mallick
 
PDF
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
PPTX
Data Structure - Elementary Data Organization
Uma mohan
 
PPTX
Set data structure
Tech_MX
 
PPTX
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
PPT
Data Structure and Algorithms
ManishPrajapati78
 
PPTX
Classification of datastructure.ppt
LakshmiSamivel
 
PPTX
Analysis of algorithm
Rajendra Dangwal
 
C++ Arrays
أحمد محمد
 
Abstract data types (adt) intro to data structure part 2
Self-Employed
 
Stack using Linked List
Sayantan Sur
 
Applications of stack
eShikshak
 
Queue in Data Structure
Muhazzab Chouhadry
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Tree in data structure
ghhgj jhgh
 
Sorting algorithms
Maher Alshammari
 
stack & queue
manju rani
 
Circular link list.ppt
Tirthika Bandi
 
Binary Tree in Data Structure
Meghaj Mallick
 
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Data Structure - Elementary Data Organization
Uma mohan
 
Set data structure
Tech_MX
 
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
Data Structure and Algorithms
ManishPrajapati78
 
Classification of datastructure.ppt
LakshmiSamivel
 
Analysis of algorithm
Rajendra Dangwal
 

Similar to Intro to Data Structure & Algorithms (20)

PDF
Data structures and algorithms Module-1.pdf
DukeCalvin
 
PPTX
Basic of Data Structure - Data Structure - Notes
Omprakash Chauhan
 
PPTX
lecture1-2202211144eeeee24444444413.pptx
smartashammari
 
PPTX
lecture1-220221114413Algorithims and data structures.pptx
smartashammari
 
PPTX
Algorithms and Data Structures
sonykhan3
 
PPTX
Data Structure and Algorithms
iqbalphy1
 
PPTX
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
PPTX
RAJAT PROJECT.pptx
SayedMohdAsim2
 
PPTX
Unit 1 abstract data types
LavanyaJ28
 
PDF
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
prathamsingh33
 
PPT
Lec1.ppt
ssuser8bddb2
 
PPTX
data structures and its importance
Anaya Zafar
 
PPSX
Data Structure and Algorithm Chapter 1.ppsx
SolomonEndalu
 
PPTX
Analysis of Algorithms_RR.pptx
KarthikR780430
 
PPTX
Data structure introduction
NavneetSandhu0
 
DOCX
Data structure and algorithm.
Abdul salam
 
PPT
algo 1.ppt
example43
 
PPT
part 1 - intorduction data structure 2021 mte.ppt
abdoSelem1
 
Data structures and algorithms Module-1.pdf
DukeCalvin
 
Basic of Data Structure - Data Structure - Notes
Omprakash Chauhan
 
lecture1-2202211144eeeee24444444413.pptx
smartashammari
 
lecture1-220221114413Algorithims and data structures.pptx
smartashammari
 
Algorithms and Data Structures
sonykhan3
 
Data Structure and Algorithms
iqbalphy1
 
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
RAJAT PROJECT.pptx
SayedMohdAsim2
 
Unit 1 abstract data types
LavanyaJ28
 
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
prathamsingh33
 
Lec1.ppt
ssuser8bddb2
 
data structures and its importance
Anaya Zafar
 
Data Structure and Algorithm Chapter 1.ppsx
SolomonEndalu
 
Analysis of Algorithms_RR.pptx
KarthikR780430
 
Data structure introduction
NavneetSandhu0
 
Data structure and algorithm.
Abdul salam
 
algo 1.ppt
example43
 
part 1 - intorduction data structure 2021 mte.ppt
abdoSelem1
 
Ad

More from Akhil Kaushik (20)

PPT
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
PPTX
Code Optimization
Akhil Kaushik
 
PPTX
Parsing in Compiler Design
Akhil Kaushik
 
PPTX
Context Free Grammar
Akhil Kaushik
 
PPTX
Error Detection & Recovery
Akhil Kaushik
 
PPTX
Symbol Table
Akhil Kaushik
 
PPTX
Lexical Analyzer Implementation
Akhil Kaushik
 
PPTX
NFA & DFA
Akhil Kaushik
 
PPTX
Lexical Analysis - Compiler Design
Akhil Kaushik
 
PPTX
File Handling Python
Akhil Kaushik
 
PPTX
Regular Expressions
Akhil Kaushik
 
PPTX
Algorithms & Complexity Calculation
Akhil Kaushik
 
PPTX
Decision Making & Loops
Akhil Kaushik
 
PPTX
Basic programs in Python
Akhil Kaushik
 
PPTX
Python Data-Types
Akhil Kaushik
 
PPTX
Introduction to Python Programming
Akhil Kaushik
 
PPT
Compiler Design Basics
Akhil Kaushik
 
PPTX
Bootstrapping in Compiler
Akhil Kaushik
 
PPTX
Compiler construction tools
Akhil Kaushik
 
PPTX
Phases of compiler
Akhil Kaushik
 
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Code Optimization
Akhil Kaushik
 
Parsing in Compiler Design
Akhil Kaushik
 
Context Free Grammar
Akhil Kaushik
 
Error Detection & Recovery
Akhil Kaushik
 
Symbol Table
Akhil Kaushik
 
Lexical Analyzer Implementation
Akhil Kaushik
 
NFA & DFA
Akhil Kaushik
 
Lexical Analysis - Compiler Design
Akhil Kaushik
 
File Handling Python
Akhil Kaushik
 
Regular Expressions
Akhil Kaushik
 
Algorithms & Complexity Calculation
Akhil Kaushik
 
Decision Making & Loops
Akhil Kaushik
 
Basic programs in Python
Akhil Kaushik
 
Python Data-Types
Akhil Kaushik
 
Introduction to Python Programming
Akhil Kaushik
 
Compiler Design Basics
Akhil Kaushik
 
Bootstrapping in Compiler
Akhil Kaushik
 
Compiler construction tools
Akhil Kaushik
 
Phases of compiler
Akhil Kaushik
 
Ad

Recently uploaded (20)

PPTX
Matatag Curriculum English 8-Week 1 Day 1-5.pptx
KirbieJaneGasta1
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
DOCX
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
PPTX
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 
PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
Practice Gardens and Polytechnic Education: Utilizing Nature in 1950s’ Hu...
Lajos Somogyvári
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PPTX
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PDF
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
PDF
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
PPTX
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
Matatag Curriculum English 8-Week 1 Day 1-5.pptx
KirbieJaneGasta1
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
Practice Gardens and Polytechnic Education: Utilizing Nature in 1950s’ Hu...
Lajos Somogyvári
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 

Intro to Data Structure & Algorithms

  • 1. Introduction to Data Structure & Algorithms Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani
  • 2. Good Computer Program • A computer program is a series of instructions to carry out a particular task written in a language that a computer can understand. • There are a number of features for a good program:- – Run efficiently and correctly – Have a user friendly interface – Be easy to read and understand – Be easy to debug – Be easy to modify – Be easy to maintain
  • 3. Good Computer Program • Programs consists of two things: Algorithms and data structures. • A good program is a combination of both algorithm and a data structure. • An algorithm is a step by step recipe for solving an instance of a problem.
  • 4. What are Data Structures? • Data structures defines a way of organizing all data items that consider not only the elements stored but also stores the relationship between the elements. • A data structure represents the logical relationship that exists between individual elements of data to carry out certain tasks.
  • 5. What are Data Structures? • In simple language, Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily. • Ex: Store runs according to a Batsman’s name.
  • 6. Why study Data Structures? • To identify and develop useful mathematical entities and operations and to determine what class of problem can be solved by them. • To determine representation of abstract entities and to implement the abstract operations on these representations
  • 7. Data Type vs Data Structure • Data type: data type a set of values that variable may assume. Int, float, char, double, Boolean. • Data Structure: extension of data type i.e. the implementation of organized data and operations allowed on data type.
  • 8. Why study Data Structures? • DS are used in almost every program or software. • DS study is mandatory to develop better algorithm. • DS allow management of large database and internet indexing services.
  • 9. Why study Data Structures? Study of DS includes:- • Logical description of DS • Implementation of DS • Quantitative analysis of DS
  • 10. Why study Data Structures? Applications of DS are in every are including:- • DBMS • SIMULATION • GRAPHICS • NETWORK ANALYSIS • NUMERICAL ANALYSIS • COMPILER DESIGN • OPERATING SYSTEM • ARTIFICAL INTELLIGENCE
  • 11. Data Structure Classification Classification can be done on the basis of :- 1. According to nature of size 2. According to its occurrence 3. Primitive and non-primitive
  • 13. STATIC AND DYNAMIC 1. Static: Here we can store data up to a fixed no. only. Ex: array. 2. Dynamic: It allows programmer to change its size during program execution to add or delete data. Ex: linked list, tree, etc.
  • 14. LINEAR AND NON-LINEAR 1. Linear: Here data is stored in consecutive memory allocation i.e. - sequentially. Ex: array, linked list, queue, etc. 2. Non-linear: Here data is in no sequential form and usually used to identify hierarchical relationship. Ex: Trees
  • 15. PRIMITIVE AND NON-PRIMITIVE PRIMITIVE DATATYPE: These data types are used to represent single values. • Integer: This is used to represent a number without decimal point. Ex: 12, 90 • Float and Double: This is used to represent a number with decimal point. Ex: 45.1, 67.3 • Character : This is used to represent single character Ex: ‘C’, ‘a’ • String: This is used to represent group of characters. Ex: “Stephen College" NON-PRIMITIVE DATATYPES: The data types that are derived from primary data types are known as non-Primitive data types. • These data types are used to store group of values. • The non-primitive data types are – Arrays – Structure – Union – linked list – Stacks
  • 16. Homogenous vs Hetrogenous • Homogenous: DS refer to the data structure which store same type of elements. Ex: arrays • Non-homogenous: DS refer to the data structure which store data of different type of elements. Ex: structure.
  • 17. Operations on Data Structure 1. Traversing: Accessing each records exactly once so that certain items in the record may be processed. 2. Searching: Finding the location of a particular record with a given key value, or finding the location of all records which satisfy one or more conditions. 3. Inserting: Adding a new record to the structure. 4. Deleting: Removing the record from the structure. 5. Sorting: Managing the data or record in some logical order(Ascending or descending order). 6. Merging: Combining the record in two different sorted files into a single sorted file. 7. Create, delete, update, etc.
  • 18. Algorithms • An algorithm is a step by step recipe for solving an instance of a problem. • An algorithm is a precise procedure for solving a problem in finite number of steps. • An algorithm states the actions to be executed and the order in which these actions are to be executed.
  • 19. Algorithms • An algorithm possesses the following properties:- – It must be correct. – It must be composed of a finite number of steps. – There can be no ambiguity as to which step will be done next. – It must terminate. – It takes zero or more inputs – It should be efficient and flexible – It should use less memory space as much as possible – It results in one or more outputs
  • 20. Various steps in developing Algorithms • Devising the Algorithm:- Each step of an algorithm must be precisely defined and no vague statements should be used. – Pseudo code is used to describe the algorithm, in less formal language than a Programming language
  • 21. Various steps in developing Algorithms • Validating the Algorithm: The proof of correctness of the algorithm. – A human must be able to perform each step by giving the required input, use the algorithm and get the required output in a finite amount of time. • Expressing the algorithm: To implement the algorithm in a programming language. – The algorithm used should terminate after a finite number of steps.
  • 22. Efficiency of an Algorithm An algorithm should meet three things:- • It should be independent of the programming language in which the idea is realized • Every programmer having enough knowledge and experience should understand it • It should be applicable to inputs of all sizes
  • 23. Efficiency of an Algorithm • Efficiency of an algorithm denotes the rate at which an algorithm solves a problem of size ‘n’. • It is measured by the amount of resources it uses, the time and the space. • An algorithm’s complexity is measured by calculating the time taken and space required for performing the algorithm.
  • 24. Space Complexity of an Algorithm • It is the way in which the amount of storage space required by an algorithm varies with the size of the problem to be solved. • The space occupied by the program is generally by the following:- – A fixed amount of memory for the program code. – A variable amount of memory for variable. This space increases or decreases depending upon whether the program uses iterative or recursive procedures.
  • 25. Space Complexity of an Algorithm • Instruction Space is the space occupied by the compiled version of the program. • Data Space is the space used to hold the variables , data structures, allocated memory and other data elements. • Environment Space is the space used on the run time stack for each function call.
  • 26. Time Complexity of an Algorithm • The way in which the number of steps required by an algo varies with the size of the problem it is solving.
  • 27. Time Complexity of an Algorithm • It is the amount of time needed by a program to complete its task. • The time taken for an algorithm is comprised of two times:- – Compilation Time – Run Time
  • 28. Time Complexity of an Algorithm • Compilation time is the time taken to compile an algorithm. • While compiling it checks for the syntax and semantic errors in the program and links it with the standard libraries, your program has asked to. • It comes under the domain of computer science (software dependent).
  • 29. Time Complexity of an Algorithm • Runtime is the time to execute the compiled program. • Note that run time is calculated only for executable statements and not for declaration statements. • It comes under the domain of electronics (depends on hardware).
  • 30. Time Complexity of an Algorithm • It can be defined for computation of function f() as a total number of statements that are executed for computing the value of f(n). • Time complexity of an algorithm is generally classified as three types:- (i) Worst case (ii) Average Case (iii) Best Case
  • 31. Time Complexity of an Algorithm • Worst Case: It is the longest time that an algorithm will use over all instances of size ‘n’ for a given problem to produce a desired result. – Denoted by Big-Oh (O) • Average Case: It is the average time(or average space). – Denoted by theta (Θ). • Best Case: It is the shortest time (or least space). – Denoted by Omega(Ω).
  • 32. Time Complexity of an Algorithm
  • 33. Time Complexity of an Algorithm fact ( long n) { for (i=1; i<=n; i++) x=i*x; return x; } • Data Space: i, n and x • Environment Space: Almost nothing because the function is called only once. • The algorithm has a complexity of O(1) because it does not depend on n. • No matter how big the problem becomes, the space complexity remains the same since the same variables are used, and the function is called only once.
  • 34. Time Complexity of an Algorithm long fact (long x) { if (x<=1) return(1); else return (x * fact(x-1)); } • Data space : x • Environment Space: fact() is called recursively , and so the amount of space this program used is based on the size of the problem.
  • 35. Measure Algorithms’ Performance • It needs programs to create ,append, update the database, print data, permit online enquiry and so on. • A Programmer should identify all requirements to solve the problem like:- – Type of Programming language – Narration of the program describing the tasks to be performed – Frequency of Processing (hourly, daily, weekly etc) – Input and output of the program – Limitations and restrictions for the program
  • 36. Measure Algorithms’ Performance • What metric should be used to judge algorithms? – Length of the program (lines of code) – Ease of programming (bugs, maintenance) – Memory required – Running time *Running time is the dominant standard. – Quantifiable and easy to compare – Often the critical bottleneck
  • 37. CONTACT ME AT: Akhil Kaushik [email protected] 9416910303 CONTACT ME AT: Akhil Kaushik [email protected] 9416910303 Thank You !!!