SlideShare a Scribd company logo
Analysis of Algorithm
Mr. Mr. Fazl-e-Basit
Prof. Dr. Awais Adnan
Lecture 01: Introduction
Mr. Fazl-e-Basit
Origin of word: Algorithm
‱ The word Algorithm comes from the name of the muslim author Abu
Ja’far Mohammad ibn Musa-al-Khowarizmi. He was born in the
eighth century at Khwarizm (Kheva), a town south of river Oxus in
present Uzbekistan. Uzbekistan, a Muslim country for over a
thousand years, was taken over by the Russians in 1873.
‱ Much of al-Khwarizmi’s work was written in a book titled al Kitab al-
mukhatasar fi hisab al-jabrwa’l-muqabalah (The Compendious Book
on Calculation by Completion and Balancing). It is from the titles of
these writings and his name that the words algebra and algorithm are
derived. As a result of his work, al-Khwarizmi is regarded as the most
outstanding mathematician of his time
Mr. Fazl-e-Basit
‱ Informally, an algorithm is any well-defined computational
procedure that takes some value or set of values as input and
produce some value or set of values as output.
or
‱ We can also view an algorithm as a tool for solving a well
specified computational problem.
or
‱ We can say algorithm is a sequence of operations to solve
problems correctly.
Algorithm?
Mr. Fazl-e-Basit
Examples of everyday algorithms:
‱ Recipe for baking a cake
‱ Instructions for assembling furniture
‱ Steps for solving a math problem
‱ Sorting a deck of cards
‱
‱
‱
Algorithms are not limited to programming but
are used in various contexts.
Mr. Fazl-e-Basit
Formal definitions of Algorithm
‱ An algorithm is a set of step-by-step instructions to accomplish a task or solve a
problem, often used in computer science.
‱ It is a well-defined procedure that takes inputs and produces outputs, following a
finite number of steps.
‱ Algorithms are used in various fields, including computer science, engineering,
finance, and artificial intelligence
‱ They can be simple or complex, depending on the desired outcome.
‱ An algorithm must meet certain characteristics, including being clear and
unambiguous, having well-defined inputs and outputs, being finite and feasible,
language-independent, and producing at least one output
‱ Algorithms can be expressed in various programming languages, but their logic
or plan for solving a problem should remain the same, regardless of the
implementation
Mr. Fazl-e-Basit
Algorithm
Step-by-step: The instructions are clear and well-defined, outlining each step
in the process.
Finite: The algorithm must terminate after a certain number of steps,
avoiding infinite loops.
Problem-solving: The instructions are designed to achieve a specific
outcome or solve a particular problem.
Think of an algorithm like a recipe.
‱ It provides a clear sequence of instructions (steps) to achieve a desired
outcome (cooking a delicious meal).
‱ Just like there are many recipes for different dishes, there can be many
algorithms to solve different problems.
Mr. Fazl-e-Basit
7
Example: Algorithms to sort numbers in ascending order
Input
Merge Sort
Insertion Sort
Algorithm A
Algorithm B
Unordered List
Output
ordered List
31,41,59,26,41,58 26,31,41,41,58,59
In above figure the whole set of input numbers are known as
instance of the sorting problem.
Mr. Fazl-e-Basit
8
Data Structure
‱ A Data Structure is a systematic way of organizing and accessing data with a
specific relationship between the elements, in order to facilitate access and
modifications.
‱ No single data structure works well for all purposes, so it is important to be
familiar with pros and cons of several Data Structures.
Mr. Fazl-e-Basit
9
Algorithmics
‱ It is the science that lets designers study and evaluate the effect of
algorithms based on various factors so that the best algorithm is selected
to meet a particular task in given circumstances.
‱ It is also the science that tells how to design a new algorithm for a
particular job.
Mr. Fazl-e-Basit
Example of algorithm
‱ Division ( N1/N2)
‱ Step 1: the user enters the first and second numbers – the dividend and the divisor
‱ Step 2: the algorithm written to perform the division takes in the number, then puts a
division sign between the dividend and the divisor. It also checks for a remainder.
‱ Step 3: the result of the division and remainder is shown to the user
‱ Step 4: the algorithm terminates
‱ Division ( N1/N2)
‱ N1 
‱ N2 
‱ R  N1 / N2 // ( R = N1 Ă· N2)
‱  R
Mr. Fazl-e-Basit
Algorithm Design Strategies
‱ Divide and conquer
‱ Greedy algorithms
‱ Dynamic programming
‱ Backtracking
‱ Brute force
choosing the right algorithm design strategy
depends on the problem at hand
Mr. Fazl-e-Basit
Components and Characteristics of Algorithms
‱ Effectiveness: Algorithms should be most effective among many ways to solve a
problem.
‱ Language independent: An algorithm shouldn't include computer code. Instead,
the algorithm should be written in such a way that it can be used in different
programming languages.
‱ Efficiency: Algorithms should be designed to minimize time and resources.
‱ Correctness: Algorithms should produce the correct output for all possible inputs.
Input: Algorithm takes defined and precise input
Output: Algorithm returns (provides) an output(s)
Steps: Each step in the algorithm should be clear and unambiguous.
Components
Characteristics
Mr. Fazl-e-Basit
Language independence: Pseudocode
‱ A Pseudocode is defined as a step-by-step description of an algorithm.
Pseudocode does not use any programming language in its
representation instead it uses the simple English language text as it is
intended for human understanding rather than machine reading.
‱ Pseudocode is the intermediate state between an idea and its
implementation(code) in a high-level language.
‱ Pseudocode is a high-level description of an algorithm using a
combination of natural language and programming-like syntax.
‱ It helps in planning and designing algorithms before actual
implementation in a programming language.
Mr. Fazl-e-Basit
Algorithm Analysis
‱ Importance of algorithm analysis:
‱ Evaluates the efficiency and performance of algorithms.
‱ Helps in comparing different algorithms for the same problem.
‱ Target metrics for algorithm analysis:
‱ Time complexity: Measures the time taken by an algorithm to run as a
function of input size.
‱ Space complexity: Measures the memory space required by an algorithm as a
function of input size.
Mr. Fazl-e-Basit
Time and Space Complexity
‱ Time complexity:
‱ Big O notation: Represents the upper bound on the growth rate of
an algorithm in terms of its input size.
‱ Examples of common time complexities (O(1), O(log n), O(n),
O(n^2), O(2^n), etc.).
‱ Space Complexity
‱ Measures the amount of memory required by an algorithm as it
executes.
‱ Similar notation as time complexity (O(1), O(n), O(n^2), etc.).
Mr. Fazl-e-Basit
16
How do we Analyze?
‱ Every Algorithm has a parameter N or n that effects its
running time.
‱ For example, for sorting different numbers the parameter N is
the number of input numbers to be sorted.
‱ So for analyzing algorithms our starting point is to have n or N
N or n → shows size of the Input.
Mr. Fazl-e-Basit
Hard Problems
‱ Most of the contents of this course are about to
address/discuss algorithms and their efficiency. Our usual
measure of efficiency is speed.
‱ There are some problems, however, for which no efficient
solution is known.
‱ We will study few of these kind of problems later in the
course, which are known as NP-Complete problems.
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 18
Parameters for Selection of an Algorithm
‱ Priority of Task
‱ Type of Available Computing Equipment
‱ Nature of Problem
‱ Speed of Execution
‱ Storage Requirement
‱ Programming Effort
A good choice can save both money and time,
and can successfully solve the problem.
Growth of Functions –
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 20
Growth of Functions
‱ We can sometimes determine the exact running time of the
algorithm, however`r, the extra precision is not usually worth
the effort of computing it.
‱ For large inputs, the multiplicative constants and lower order
terms of an exact running time are dominated by the effects of
the input size itself.
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 21
Things to consider when Analyzing Algorithms
1. Ignore constants. For example,
f(n) = 25nÂČ
or
f(n) = 25nÂČ + 2000
f(n) = O (nÂČ)
2. Ignore small terms
f(n) = 25nÂł+ 30nÂČ + 10n
f(n) = O (nÂł)
3. Application Independent
i.e. not dependent on any tool, platform or application.
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 22
Asymptotic Performance
‱ In this course, we care most about asymptotic performance.
i.e.
‱ How does the algorithm behave as the problem size gets very
large?
‱ Running time
‱ Memory/storage requirements
‱ Bandwidth/power requirements/logic gates/etc.
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 23
‱ When we look at the input sizes large enough to make only the order
of growth of the running time relevant, we are studying the asymptotic
efficiency of the algorithm.
‱ That is we are concerned with how the running time of the algorithm
increases with the size of the input in the limit, as the size of the input
increases without any bound.
‱ We will study standard methods for simplifying the asymptotic analysis
of the algorithm. We will begin with by defining several types of
“asymptotic notations” like Theta ( Θ ) Notation, Big-Oh ( O ) Notation
and Omega ( ℩ ) Notation.
Asymptotic Performance
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 24
Theta Notation ( Θ )
‱ For a given function g(n), we denote by Θ( g(n) ) the set of functions
Θ( g(n) ) = { f(n) : there exist positive constants c1,c2 and
n0 such that
0 ≀ c1.g(n) ≀ f(n) ≀ c2.g(n) for all n ≄ n0 }1
1 colon in set means “such that”
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 25
‱ A function f(n) belongs to the set Θ( g(n) ) if there exist positive
constants c1 and c2 such that it can be sandwiched between c1g(n)
and c2g(n) for sufficiently large n.
‱ Since Θ( g(n) ) is a set, we could write
f(n) Є Θ( g(n) ) to indicate that f(n) is a member of Θ( g(n) ). Instead
we will usually write
f(n) = Θ( g(n) ).
Є means “belongs to”
Theta Notation ( Θ )
Mr. Fazl-e-Basit
25 April 2024
Instructor:- Mr. Fazl-e-Basit 26
C2.g(n)
f(n)
n0 n
C1.g(n)
f(n) = Θ( g(n) )
‱ In the above figure, for all values of n to the right of n0, the value of f(n)
lies at or above C1.g(n) and at or below C2.g(n).
‱ In other words, for all n ≄ n0, the function f(n) is equal to g(n) to within
constant factor.
‱ We say that g(n) is asymptotic tight bound for f(n).
Theta Notation ( Θ )
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 27
‱ Lets us justify this intuition by using the formal definition to show that
f(n) = n2/2-3n = Θ( n2 ).
‱ To do so we must find the constants c1,c2, and n0 such that
c1.n2 ≀ n2/2-3n ≀ c2.n2
for all n ≄ n0. dividing by n2
c1 ≀ 1/2-3/n ≀ c2
The right hand side inequality can be made to hold for any value of n ≄ 1 by
choosing c2 ≄ œ.
Likewise , the left hand side inequality can be made to hold for any value of
n ≄ 7 by choosing c1 ≀ 1/14. Thus, by choosing c1=1/14 , c2=1/2 and
n0 = 7, we can verify that n2/2-3n = Θ( n2 ).
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 28
‱ In above example, certainly other choices for the constants exist, but the
important thing is that some choice exists.
‱ Since any constant is a degree-0 polynomial, we can express any constant
function as Θ( n0 ) or Θ( 1 ). We shall always use the notation Θ( 1 ) to
mean either constant or constant function with respective to some
variable.
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 29
Big-Oh Notation (O )
‱ When we have only an asymptotic upper bound, we use O – notation. For a
given function g(n), we denote by O( g(n) ) the set of functions
O( g(n) ) = { f(n) : there exist positive constants c, and n0 such
that
0 ≀ f(n) ≀ c.g(n) for all n ≄ n0 }1
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 30
c.g(n)
f(n)
n0 n
f(n) = O( g(n) )
Big-Oh Notation (O )
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 31
‱ We write f(n) = O( g(n) ) to indicate that f(n) is a member of the set O( g(n) ).
‱ Note that f(n) = Θ( g(n) ) implies f(n) = O( g(n) ), since Θ notation is stronger
notation than O notation. So for quadratic function an2+bn + c, where a>0, is
in Θ( n2 ) also shows that any quadratic function is in O( n2 ).
Big-Oh Notation (O )
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 32
Omega Notation ( ℩ )
‱ Just as O-notation provides an upper bound on a function, ℩
notation provides an asymptotic lower bound.
‱ For a given function g(n), we denote by ℩( g(n) ) the set of
functions
℩( g(n) ) = { f(n) : there exist positive constants
c, and n0 such that
0 ≀ c.g(n) ≀ f(n) for all n ≄ n0 }1
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 33
c.g(n)
f(n)
n
n0
f(n) = ℩( g(n) )
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 34
Example:
‱ Objective is to find the maximum of an unordered set having N
elements.
‱ Input : An unordered list.
‱ Output : Maximum of input set.
‱ Algorithm
1. int Max = 0 //assume S[N] is filled with +ve numbers
2. For (int I = 0;I<N;I++)
3. {
4. If (S[I] > Max)
5. Max = S[I]
6. }
7. cout<< Max
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 35
Simple Analysis of previous Algorithm
Instruction No of times Executed cost
1 1 1
2 N N
3 - -
4 N N
5 N N
6 - -
7 1 1
So f(n) = 1 + N + N + N + 1 = 2 + 3N = 3N+2
so f(n) = O (N) or O (n)
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 36
NOTE : we always look for worst case of each instruction to be
executed while finding Big-Oh (O). (Assume all instructions take
unit time in above example).
‱ The worst case running time of an algorithm is an upper bound on
the running time for an input.
‱ Knowing it, gives us guarantee that algorithm will never take any
longer.
‱ We need not make some educated guess about the running time
and hope that it never gets much worse.
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 37
Types of Functions (Bounding Functions )
1. Constant Function: O ( 1 )
For example, addition of two numbers will take same for Worst case, Best case and
Average case.
2. Logarithmic Function: O ( log(n) )
3. Linear Function : O ( n )
4. O ( n.log(n) )
5. Quadratic Function : O (nÂČ)
6. Cubic Function : O ( nÂł )
7. Polynomial Function : O ( nk )
8. Exponential Function : O ( 2n )
etc

Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 38
Some facts about summation
‱ If c is a constant
And
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 39
Mathematical Series
➱ If 0 < x < 1 then this is Θ(1), and if x > 1, then this is Θ(xn).
Mr. Fazl-e-Basit
Harmonic series For n ≄ 0
25 April 2024 Instructor:- Mr. Fazl-e-Basit 41
Analysis: A Harder Example
➱ Let us consider a harder example.
➱ How do we analyze the running time of an algorithm that has complex nested
loop? The answer is we write out the loops as summations and then solve the
summations. To convert loops into summations, we work from inside-out.
Mr. Fazl-e-Basit
25 April 2024 Instructor:- Mr. Fazl-e-Basit 42
‱ Consider the inner most while loop.
‱ It is executed for k = j, j - 1, j - 2, . . . , 0. Time spent inside the while
loop is constant. Let I() be the time spent in the while loop. Thus
➱ Consider the middle for loop.
➱ Its running time is determined by i.
Let M() be the time spent in the for loop:
25 April 2024 Instructor:- Mr. Fazl-e-Basit 43
25 April 2024 Instructor:- Mr. Fazl-e-Basit 44
➱ Finally the outer-most for loop.
➱ Let T() be running time of the entire algorithm
Mr. Fazl-e-Basit
Some searching and sorting
Searching Algorithms
‱ Linear search
‱ Binary search
‱ Hashing
Sorting Algorithms
‱ Bubble sort
‱ Insertion sort
‱ Selection sort
‱ Merge sort
‱ Quick sort
‱ Heap sort
Mr. Fazl-e-Basit
Search
Complete Search
(Exhaustive
Search):
Linear
Direct Search
Linear/sequential
Search Binary Search
Non-linear
Partial Search
(Heuristic Search):
A Search*:
Greedy Best-First
Search
Hill Climbing:
Other Techniques
. . . . . .
Ad

More Related Content

Similar to 01 Revision Introduction SLides Od Design ANd Aalaysis Of aLgo (20)

Unit 1, ADA.pptx
Unit 1, ADA.pptxUnit 1, ADA.pptx
Unit 1, ADA.pptx
jinkhatima
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
NayanChandak1
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptChapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Tekle12
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptChapter1.1 Introduction.ppt
Chapter1.1 Introduction.ppt
Tekle12
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 
lect 1-ds algo(final)_2.pdf
lect 1-ds  algo(final)_2.pdflect 1-ds  algo(final)_2.pdf
lect 1-ds algo(final)_2.pdf
MuhammadUmerIhtisham
 
problem solving and algorithm development
problem solving and algorithm developmentproblem solving and algorithm development
problem solving and algorithm development
jessicajames100
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPTANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
Design and Analysis of Algorithm for II year Computer science and Engineering...
Design and Analysis of Algorithm for II year Computer science and Engineering...Design and Analysis of Algorithm for II year Computer science and Engineering...
Design and Analysis of Algorithm for II year Computer science and Engineering...
Kalpana Devi M
 
3733-lecture-1_design-and-analysis-of-algorithms.pptx
3733-lecture-1_design-and-analysis-of-algorithms.pptx3733-lecture-1_design-and-analysis-of-algorithms.pptx
3733-lecture-1_design-and-analysis-of-algorithms.pptx
sankar00001
 
Lecture 11234567890qwertyuiodfghjdfgh.pptx
Lecture 11234567890qwertyuiodfghjdfgh.pptxLecture 11234567890qwertyuiodfghjdfgh.pptx
Lecture 11234567890qwertyuiodfghjdfgh.pptx
IfraLuqman
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffdPROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
Krishnan MuthuManickam
 
Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptx
ShaistaRiaz4
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
Akhil Kaushik
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
Chapter-1-Introduction-to-Aglorithms.pdf
Chapter-1-Introduction-to-Aglorithms.pdfChapter-1-Introduction-to-Aglorithms.pdf
Chapter-1-Introduction-to-Aglorithms.pdf
Shanmuganathan C
 
Unit 1, ADA.pptx
Unit 1, ADA.pptxUnit 1, ADA.pptx
Unit 1, ADA.pptx
jinkhatima
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
NayanChandak1
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptChapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Tekle12
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptChapter1.1 Introduction.ppt
Chapter1.1 Introduction.ppt
Tekle12
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 
problem solving and algorithm development
problem solving and algorithm developmentproblem solving and algorithm development
problem solving and algorithm development
jessicajames100
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPTANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
Design and Analysis of Algorithm for II year Computer science and Engineering...
Design and Analysis of Algorithm for II year Computer science and Engineering...Design and Analysis of Algorithm for II year Computer science and Engineering...
Design and Analysis of Algorithm for II year Computer science and Engineering...
Kalpana Devi M
 
3733-lecture-1_design-and-analysis-of-algorithms.pptx
3733-lecture-1_design-and-analysis-of-algorithms.pptx3733-lecture-1_design-and-analysis-of-algorithms.pptx
3733-lecture-1_design-and-analysis-of-algorithms.pptx
sankar00001
 
Lecture 11234567890qwertyuiodfghjdfgh.pptx
Lecture 11234567890qwertyuiodfghjdfgh.pptxLecture 11234567890qwertyuiodfghjdfgh.pptx
Lecture 11234567890qwertyuiodfghjdfgh.pptx
IfraLuqman
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffdPROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
Krishnan MuthuManickam
 
Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptx
ShaistaRiaz4
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
Akhil Kaushik
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
Chapter-1-Introduction-to-Aglorithms.pdf
Chapter-1-Introduction-to-Aglorithms.pdfChapter-1-Introduction-to-Aglorithms.pdf
Chapter-1-Introduction-to-Aglorithms.pdf
Shanmuganathan C
 

Recently uploaded (20)

Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Ad

01 Revision Introduction SLides Od Design ANd Aalaysis Of aLgo

  • 1. Analysis of Algorithm Mr. Mr. Fazl-e-Basit Prof. Dr. Awais Adnan Lecture 01: Introduction
  • 2. Mr. Fazl-e-Basit Origin of word: Algorithm ‱ The word Algorithm comes from the name of the muslim author Abu Ja’far Mohammad ibn Musa-al-Khowarizmi. He was born in the eighth century at Khwarizm (Kheva), a town south of river Oxus in present Uzbekistan. Uzbekistan, a Muslim country for over a thousand years, was taken over by the Russians in 1873. ‱ Much of al-Khwarizmi’s work was written in a book titled al Kitab al- mukhatasar fi hisab al-jabrwa’l-muqabalah (The Compendious Book on Calculation by Completion and Balancing). It is from the titles of these writings and his name that the words algebra and algorithm are derived. As a result of his work, al-Khwarizmi is regarded as the most outstanding mathematician of his time
  • 3. Mr. Fazl-e-Basit ‱ Informally, an algorithm is any well-defined computational procedure that takes some value or set of values as input and produce some value or set of values as output. or ‱ We can also view an algorithm as a tool for solving a well specified computational problem. or ‱ We can say algorithm is a sequence of operations to solve problems correctly. Algorithm?
  • 4. Mr. Fazl-e-Basit Examples of everyday algorithms: ‱ Recipe for baking a cake ‱ Instructions for assembling furniture ‱ Steps for solving a math problem ‱ Sorting a deck of cards ‱ ‱ ‱ Algorithms are not limited to programming but are used in various contexts.
  • 5. Mr. Fazl-e-Basit Formal definitions of Algorithm ‱ An algorithm is a set of step-by-step instructions to accomplish a task or solve a problem, often used in computer science. ‱ It is a well-defined procedure that takes inputs and produces outputs, following a finite number of steps. ‱ Algorithms are used in various fields, including computer science, engineering, finance, and artificial intelligence ‱ They can be simple or complex, depending on the desired outcome. ‱ An algorithm must meet certain characteristics, including being clear and unambiguous, having well-defined inputs and outputs, being finite and feasible, language-independent, and producing at least one output ‱ Algorithms can be expressed in various programming languages, but their logic or plan for solving a problem should remain the same, regardless of the implementation
  • 6. Mr. Fazl-e-Basit Algorithm Step-by-step: The instructions are clear and well-defined, outlining each step in the process. Finite: The algorithm must terminate after a certain number of steps, avoiding infinite loops. Problem-solving: The instructions are designed to achieve a specific outcome or solve a particular problem. Think of an algorithm like a recipe. ‱ It provides a clear sequence of instructions (steps) to achieve a desired outcome (cooking a delicious meal). ‱ Just like there are many recipes for different dishes, there can be many algorithms to solve different problems.
  • 7. Mr. Fazl-e-Basit 7 Example: Algorithms to sort numbers in ascending order Input Merge Sort Insertion Sort Algorithm A Algorithm B Unordered List Output ordered List 31,41,59,26,41,58 26,31,41,41,58,59 In above figure the whole set of input numbers are known as instance of the sorting problem.
  • 8. Mr. Fazl-e-Basit 8 Data Structure ‱ A Data Structure is a systematic way of organizing and accessing data with a specific relationship between the elements, in order to facilitate access and modifications. ‱ No single data structure works well for all purposes, so it is important to be familiar with pros and cons of several Data Structures.
  • 9. Mr. Fazl-e-Basit 9 Algorithmics ‱ It is the science that lets designers study and evaluate the effect of algorithms based on various factors so that the best algorithm is selected to meet a particular task in given circumstances. ‱ It is also the science that tells how to design a new algorithm for a particular job.
  • 10. Mr. Fazl-e-Basit Example of algorithm ‱ Division ( N1/N2) ‱ Step 1: the user enters the first and second numbers – the dividend and the divisor ‱ Step 2: the algorithm written to perform the division takes in the number, then puts a division sign between the dividend and the divisor. It also checks for a remainder. ‱ Step 3: the result of the division and remainder is shown to the user ‱ Step 4: the algorithm terminates ‱ Division ( N1/N2) ‱ N1  ‱ N2  ‱ R  N1 / N2 // ( R = N1 Ă· N2) ‱  R
  • 11. Mr. Fazl-e-Basit Algorithm Design Strategies ‱ Divide and conquer ‱ Greedy algorithms ‱ Dynamic programming ‱ Backtracking ‱ Brute force choosing the right algorithm design strategy depends on the problem at hand
  • 12. Mr. Fazl-e-Basit Components and Characteristics of Algorithms ‱ Effectiveness: Algorithms should be most effective among many ways to solve a problem. ‱ Language independent: An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages. ‱ Efficiency: Algorithms should be designed to minimize time and resources. ‱ Correctness: Algorithms should produce the correct output for all possible inputs. Input: Algorithm takes defined and precise input Output: Algorithm returns (provides) an output(s) Steps: Each step in the algorithm should be clear and unambiguous. Components Characteristics
  • 13. Mr. Fazl-e-Basit Language independence: Pseudocode ‱ A Pseudocode is defined as a step-by-step description of an algorithm. Pseudocode does not use any programming language in its representation instead it uses the simple English language text as it is intended for human understanding rather than machine reading. ‱ Pseudocode is the intermediate state between an idea and its implementation(code) in a high-level language. ‱ Pseudocode is a high-level description of an algorithm using a combination of natural language and programming-like syntax. ‱ It helps in planning and designing algorithms before actual implementation in a programming language.
  • 14. Mr. Fazl-e-Basit Algorithm Analysis ‱ Importance of algorithm analysis: ‱ Evaluates the efficiency and performance of algorithms. ‱ Helps in comparing different algorithms for the same problem. ‱ Target metrics for algorithm analysis: ‱ Time complexity: Measures the time taken by an algorithm to run as a function of input size. ‱ Space complexity: Measures the memory space required by an algorithm as a function of input size.
  • 15. Mr. Fazl-e-Basit Time and Space Complexity ‱ Time complexity: ‱ Big O notation: Represents the upper bound on the growth rate of an algorithm in terms of its input size. ‱ Examples of common time complexities (O(1), O(log n), O(n), O(n^2), O(2^n), etc.). ‱ Space Complexity ‱ Measures the amount of memory required by an algorithm as it executes. ‱ Similar notation as time complexity (O(1), O(n), O(n^2), etc.).
  • 16. Mr. Fazl-e-Basit 16 How do we Analyze? ‱ Every Algorithm has a parameter N or n that effects its running time. ‱ For example, for sorting different numbers the parameter N is the number of input numbers to be sorted. ‱ So for analyzing algorithms our starting point is to have n or N N or n → shows size of the Input.
  • 17. Mr. Fazl-e-Basit Hard Problems ‱ Most of the contents of this course are about to address/discuss algorithms and their efficiency. Our usual measure of efficiency is speed. ‱ There are some problems, however, for which no efficient solution is known. ‱ We will study few of these kind of problems later in the course, which are known as NP-Complete problems.
  • 18. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 18 Parameters for Selection of an Algorithm ‱ Priority of Task ‱ Type of Available Computing Equipment ‱ Nature of Problem ‱ Speed of Execution ‱ Storage Requirement ‱ Programming Effort A good choice can save both money and time, and can successfully solve the problem.
  • 20. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 20 Growth of Functions ‱ We can sometimes determine the exact running time of the algorithm, however`r, the extra precision is not usually worth the effort of computing it. ‱ For large inputs, the multiplicative constants and lower order terms of an exact running time are dominated by the effects of the input size itself.
  • 21. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 21 Things to consider when Analyzing Algorithms 1. Ignore constants. For example, f(n) = 25nÂČ or f(n) = 25nÂČ + 2000 f(n) = O (nÂČ) 2. Ignore small terms f(n) = 25nÂł+ 30nÂČ + 10n f(n) = O (nÂł) 3. Application Independent i.e. not dependent on any tool, platform or application.
  • 22. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 22 Asymptotic Performance ‱ In this course, we care most about asymptotic performance. i.e. ‱ How does the algorithm behave as the problem size gets very large? ‱ Running time ‱ Memory/storage requirements ‱ Bandwidth/power requirements/logic gates/etc.
  • 23. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 23 ‱ When we look at the input sizes large enough to make only the order of growth of the running time relevant, we are studying the asymptotic efficiency of the algorithm. ‱ That is we are concerned with how the running time of the algorithm increases with the size of the input in the limit, as the size of the input increases without any bound. ‱ We will study standard methods for simplifying the asymptotic analysis of the algorithm. We will begin with by defining several types of “asymptotic notations” like Theta ( Θ ) Notation, Big-Oh ( O ) Notation and Omega ( ℩ ) Notation. Asymptotic Performance
  • 24. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 24 Theta Notation ( Θ ) ‱ For a given function g(n), we denote by Θ( g(n) ) the set of functions Θ( g(n) ) = { f(n) : there exist positive constants c1,c2 and n0 such that 0 ≀ c1.g(n) ≀ f(n) ≀ c2.g(n) for all n ≄ n0 }1 1 colon in set means “such that”
  • 25. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 25 ‱ A function f(n) belongs to the set Θ( g(n) ) if there exist positive constants c1 and c2 such that it can be sandwiched between c1g(n) and c2g(n) for sufficiently large n. ‱ Since Θ( g(n) ) is a set, we could write f(n) Є Θ( g(n) ) to indicate that f(n) is a member of Θ( g(n) ). Instead we will usually write f(n) = Θ( g(n) ). Є means “belongs to” Theta Notation ( Θ )
  • 26. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 26 C2.g(n) f(n) n0 n C1.g(n) f(n) = Θ( g(n) ) ‱ In the above figure, for all values of n to the right of n0, the value of f(n) lies at or above C1.g(n) and at or below C2.g(n). ‱ In other words, for all n ≄ n0, the function f(n) is equal to g(n) to within constant factor. ‱ We say that g(n) is asymptotic tight bound for f(n). Theta Notation ( Θ )
  • 27. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 27 ‱ Lets us justify this intuition by using the formal definition to show that f(n) = n2/2-3n = Θ( n2 ). ‱ To do so we must find the constants c1,c2, and n0 such that c1.n2 ≀ n2/2-3n ≀ c2.n2 for all n ≄ n0. dividing by n2 c1 ≀ 1/2-3/n ≀ c2 The right hand side inequality can be made to hold for any value of n ≄ 1 by choosing c2 ≄ œ. Likewise , the left hand side inequality can be made to hold for any value of n ≄ 7 by choosing c1 ≀ 1/14. Thus, by choosing c1=1/14 , c2=1/2 and n0 = 7, we can verify that n2/2-3n = Θ( n2 ).
  • 28. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 28 ‱ In above example, certainly other choices for the constants exist, but the important thing is that some choice exists. ‱ Since any constant is a degree-0 polynomial, we can express any constant function as Θ( n0 ) or Θ( 1 ). We shall always use the notation Θ( 1 ) to mean either constant or constant function with respective to some variable.
  • 29. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 29 Big-Oh Notation (O ) ‱ When we have only an asymptotic upper bound, we use O – notation. For a given function g(n), we denote by O( g(n) ) the set of functions O( g(n) ) = { f(n) : there exist positive constants c, and n0 such that 0 ≀ f(n) ≀ c.g(n) for all n ≄ n0 }1
  • 30. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 30 c.g(n) f(n) n0 n f(n) = O( g(n) ) Big-Oh Notation (O )
  • 31. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 31 ‱ We write f(n) = O( g(n) ) to indicate that f(n) is a member of the set O( g(n) ). ‱ Note that f(n) = Θ( g(n) ) implies f(n) = O( g(n) ), since Θ notation is stronger notation than O notation. So for quadratic function an2+bn + c, where a>0, is in Θ( n2 ) also shows that any quadratic function is in O( n2 ). Big-Oh Notation (O )
  • 32. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 32 Omega Notation ( ℩ ) ‱ Just as O-notation provides an upper bound on a function, ℩ notation provides an asymptotic lower bound. ‱ For a given function g(n), we denote by ℩( g(n) ) the set of functions ℩( g(n) ) = { f(n) : there exist positive constants c, and n0 such that 0 ≀ c.g(n) ≀ f(n) for all n ≄ n0 }1
  • 33. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 33 c.g(n) f(n) n n0 f(n) = ℩( g(n) )
  • 34. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 34 Example: ‱ Objective is to find the maximum of an unordered set having N elements. ‱ Input : An unordered list. ‱ Output : Maximum of input set. ‱ Algorithm 1. int Max = 0 //assume S[N] is filled with +ve numbers 2. For (int I = 0;I<N;I++) 3. { 4. If (S[I] > Max) 5. Max = S[I] 6. } 7. cout<< Max
  • 35. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 35 Simple Analysis of previous Algorithm Instruction No of times Executed cost 1 1 1 2 N N 3 - - 4 N N 5 N N 6 - - 7 1 1 So f(n) = 1 + N + N + N + 1 = 2 + 3N = 3N+2 so f(n) = O (N) or O (n)
  • 36. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 36 NOTE : we always look for worst case of each instruction to be executed while finding Big-Oh (O). (Assume all instructions take unit time in above example). ‱ The worst case running time of an algorithm is an upper bound on the running time for an input. ‱ Knowing it, gives us guarantee that algorithm will never take any longer. ‱ We need not make some educated guess about the running time and hope that it never gets much worse.
  • 37. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 37 Types of Functions (Bounding Functions ) 1. Constant Function: O ( 1 ) For example, addition of two numbers will take same for Worst case, Best case and Average case. 2. Logarithmic Function: O ( log(n) ) 3. Linear Function : O ( n ) 4. O ( n.log(n) ) 5. Quadratic Function : O (nÂČ) 6. Cubic Function : O ( nÂł ) 7. Polynomial Function : O ( nk ) 8. Exponential Function : O ( 2n ) etc

  • 38. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 38 Some facts about summation ‱ If c is a constant And
  • 39. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 39 Mathematical Series ➱ If 0 < x < 1 then this is Θ(1), and if x > 1, then this is Θ(xn).
  • 41. 25 April 2024 Instructor:- Mr. Fazl-e-Basit 41 Analysis: A Harder Example ➱ Let us consider a harder example. ➱ How do we analyze the running time of an algorithm that has complex nested loop? The answer is we write out the loops as summations and then solve the summations. To convert loops into summations, we work from inside-out.
  • 42. Mr. Fazl-e-Basit 25 April 2024 Instructor:- Mr. Fazl-e-Basit 42 ‱ Consider the inner most while loop. ‱ It is executed for k = j, j - 1, j - 2, . . . , 0. Time spent inside the while loop is constant. Let I() be the time spent in the while loop. Thus
  • 43. ➱ Consider the middle for loop. ➱ Its running time is determined by i. Let M() be the time spent in the for loop: 25 April 2024 Instructor:- Mr. Fazl-e-Basit 43
  • 44. 25 April 2024 Instructor:- Mr. Fazl-e-Basit 44 ➱ Finally the outer-most for loop. ➱ Let T() be running time of the entire algorithm
  • 45. Mr. Fazl-e-Basit Some searching and sorting Searching Algorithms ‱ Linear search ‱ Binary search ‱ Hashing Sorting Algorithms ‱ Bubble sort ‱ Insertion sort ‱ Selection sort ‱ Merge sort ‱ Quick sort ‱ Heap sort
  • 46. Mr. Fazl-e-Basit Search Complete Search (Exhaustive Search): Linear Direct Search Linear/sequential Search Binary Search Non-linear Partial Search (Heuristic Search): A Search*: Greedy Best-First Search Hill Climbing: Other Techniques . . . . . .