SlideShare a Scribd company logo
Unit - II
Algorithm
1
Prepared By:
Dabbal Singh Mahara
Unit –II: Table of Contents
• Concept and definition
• Characteristic of algorithm
• Design of algorithm
• Big O notation
2
An algorithm, named after the ninth century scholar Abu Jafar
Muhammad Ibn Musu Al-Khowarizmi, is defined as follows:
• An algorithm is a finite step-by-step procedure to achieve a
required result.
• An algorithm is a sequence of computational steps that
transform the input into the output.
• An algorithm is a precise specification of a sequence of instructions
to be carried out in order to solve a given problem. Each instruction
tells what task is to be done. There should be a finite number of
instructions in an algorithm and each instruction should be executed in
a finite amount of time.
Algorithm
3
• Input:
A number of quantities are provided to an algorithm initially
before the algorithm begins. These quantities are inputs which are
processed by the algorithm.
• Definiteness:
Each step must be clear and unambiguous that leads to a specific action.
• Effectiveness:
Each step must be carried out in finite time.
• Finiteness:
Algorithm must terminate after finite time or steps
• Output:
An algorithm must have one or more output.
• Correctness:
Correct set of output values must be produced from
the each set of inputs. For the same input data, it must
always produce the same output.
Characteristics of Algorithms
4
• An algorithm can be written in a number of ways such
as natural language, pseudo-code, or flowcharts.
Pseudo-code is a popular way to express algorithm.
• Pseudo-code is a way of expressing algorithms that
uses a mixture of English phrases and indention to make
the steps in the solution explicit
• Pseudo-code cannot be compiled nor executed, and
there are no real formatting or syntax rules.
• The benefit of pseudo-code is that it enables the
programmer to concentrate on the algorithms without
worrying about all the syntactic details of a particular
programming language and easy to convert it into
programs in any language.
• There is not any standard rules for writing algorithm.
Writing Algorithm
5
Example:
Write an algorithm to find the largest among three
different numbers entered by user.
Step 1: Start
Step 2: Declare variables a, b and c.
Step 3: Read variables a, b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
6
1. The “design” pertain to
i. The description of algorithm at an abstract level by means of a
pseudo language, and
ii. Proof of correctness that is, the algorithm solves the given
problem in all cases.
2. The “analysis” deals with performance evaluation or complexity
analysis. The complexity of an algorithm is a function describing
the efficiency of the algorithm in terms of the amount of data
the algorithm must process. That is, algorithmic complexity is a
function of problem size that refers to the rate at which required
storage or consumed time grows as input size increases. There
are two main complexity measures of the efficiency of an
algorithm: Time Complexity and Space complexity. Analysis of
algorithm in terms of efficiency allows programmers to compare
the algorithms for selecting appropriate one.
Design and Analysis of Algorithm
7
Time Complexity
8
• Time complexity is a function describing the amount of time an algorithm takes in terms
of the amount of input to the algorithm.
• That is, it is a function that refers the rate at which consumed time increases as input
size increases.
• To simplify the analysis, the time for the operations that is constant independent of
input size is ignored. Simplified analysis can be based on:
• Number of arithmetic operation performed
• Number of comparisons made
• Number of times through a loop
• Number of array elements are accessed etc.
• Although the running time of an implementation of the algorithm would depend upon
the speed of the computer, programming language, compiler etc, these technical issues
are ignored. Only how running time is increasing with increasing input size is considered
in analysis.
• When analyzing algorithm it depends upon the input data, there are three cases:
• Best case:
• Average case:
• Worst case:
• best, worst, and average cases of a given algorithm express what the resource
usage is at least, at most and on average, respectively. Usually the resource being
considered is running time, i.e. time complexity, but it could also be memory or
other resources.
9
#include <stdio.h>
// Linearly search x in arr[].
// If x is present then return the index,
// otherwise return -1
int search(int arr[], int n, int x)
{
int i;
for (i=0; i<n; i++)
{
if (arr[i] == x)
return i;
}
return -1;
}
/* Driver program to test above functions*/
int main()
{
int arr[] = {1, 10, 30, 15};
int x = 30;
int n = sizeof(arr)/sizeof(arr[0]);
printf("%d is present at index %d", x, search(arr, n, x));
getchar();
return 0;
}
Let us consider the following implementation of Linear Search.
For Linear Search
• The worst case happens when the element to be searched
(x in the above code) is not present in the array. When x is
not present, the search() functions compares it with all
the elements of arr[] one by one.
• Let us assume that all cases are uniformly distributed
(including the case of x not being present in array). So we
sum all the cases and divide the sum by (n+1).
• The best case occurs when x is present at the first
location. The number of operations in the best case is
constant (not dependent on n).
Space Complexity
10
Analysis of space complexity of an algorithm is the amount of memory it
needs to run to completion. It is the rate at which required storage space
grows as a function of input size.
The space needed by a program consists of following components:
• Instruction Space: space for code
• Data Space: space for variables, constants
• Environment stack space: return address, local variables in
called function.Example:
Algorithm Sum(a,n)
{
s:=0.0;
for i:=1 to n do
s:=s+a[i];
return s;
}
The space needed by n is one word, since it is of type integer. The space
needed by a is the space needed by variables of type array of floating point
numbers. This is at least n words, since a must be large enough to hold the n
elements to be summed. So, Ssum(n) >= (n+3), n for a[], 1 for each n, I and s).
Asymptotic Analysis
11
Big Oh Notation
• Big Oh is a characteristic scheme that measures properties of algorithm complexity
performance and/or memory requirements by eliminating constant factors.
• Big Oh notation is the formal method of expressing the upper bound of an algorithm's
running time. It's a measure of the longest amount of time it could possibly take for the
algorithm to complete.
• With big O notation we express the runtime in terms of—how quickly it grows relative
to the input, as the input gets arbitrarily large.
• It's how we compare the efficiency of different algorithms to a problem.
• Properties of Big O:
− Measuring the amount of work as it varies with the size of the data affected
− Predicting the expected overall performance of an algorithm
− Generally measured relative to other algorithms to handle the same problem
• Big O has following limitations:
− It ignores potential of constant factors in the algorithm.
− It does not try to improve algorithm, only gives the complexity.
• The exact time of an algorithm will depend on the implementation of algorithm,
amount input data, programming language, CPU speed etc.
• There is a proportionality approach to measure the time complexity in terms of
relationship between input size and number of key operations of computational
process. This type of analysis is known as asymptotic analysis.
• For asymptotic analysis we use different notations:
12
Big Oh (O) notation
When we have only asymptotic upper bound then we use O notation.
Formal definition
Let f and g be any two functions defined over set of positive integers. A
function f(n) is big oh of g(n) ), denoted as f(n)=O(g(n)), if there exists two
positive constants c and n0 such that for all n >= n0, f(n) <= c*g(n).
• O(1) is used to denote constants.
• Example:
f(n)=5n3+3n2+4 and g(n) =12n3 Then, is f(n) = O(n3)?
n F(n) g(n)
1 12 12 True
2 56 96 True
3 166 324 True
4 372 768 True
Therefore, for all n >=n0=1, c = 12, f(n) <= c*g(n) => f(n) = O(g(n)).
• Example: 2 If f(x)= 5x2+4x + 2 find big oh(O) of f(x).
Here, f(x)= 5x2+4x + 3 <= 5x2+4x2+ 2x2 = 11x2 , for all x>=1
f(x) <= c * g(x), where c =11, g(x) = x2 and x0 = 1.
Therefore, f(x) = O(x2 ).
13
Big Omega ( Ω ) notation
Big omega notation gives asymptotic lower bound.
Formal definition
Let f and g be any two functions defined over set of positive integers. A function f(n)
is big Omega of g(n) ), denoted as f(n)= Ω (g(n)), if there exists two positive
constants c and n0 such that for all n >= n0, f(n) >= c*g(n).
The above relation says that g(x) is a lower bound of f(x).
Example:
If f(n)= 3n2 +4n + 7, find big omega of f(n).
Here,
f(n)= 3n2 +4n + 7 >= 3n2 for all n>= 1.
i.e. f(n) >= c * g(n), where c = 3, n0=1
and g(n) =n2 .
Therefore, f(n) = Ω (g(n).
14
Big Theta ( Θ ) notation
When we need asymptotically tight bound then we use notation.
Formal definition
Let f and g be any two functions defined over set of positive integers. A function
f(n) is big Theta of g(n) ), denoted as f(n)= Θ (g(n)), if there exists three positive
constants c1, c2 and n0 such that for all n >= n0, c1*g(n) <= f(n) <= c2*g(n).
The above relation says that f(x) is order of g(x)
Example: f(n) = 3n2 + 4n + 7 g(n) = n2 , then prove
that f(n) = (g(n)).
Proof:
let us choose c1, c2 and n0 values as 14, 1 and 1
respectively then we can have,
f(n) <= c1*g(n), n>=n0 as 3n2 + 4n + 7 <= 14*n2 ,
and
f(n) >= c2*g(n), n>=n0 as 3n2 + 4n + 7 >= 1*n2
for all n >= 1(in both cases).
So c2*g(n) <= f(n) <= c1*g(n) is trivial.
Hence f(n) = Θ(g(n)).
15
16
17
Thank You !
18

More Related Content

PPT
Fundamentals of the Analysis of Algorithm Efficiency
PPTX
Lecture 5: Asymptotic analysis of algorithms
PDF
Introduction to Algorithms Complexity Analysis
PPT
Algorithm analysis
PPTX
Unit i basic concepts of algorithms
PPTX
Daa unit 1
PPTX
Lecture 2 data structures and algorithms
PPT
02 order of growth
Fundamentals of the Analysis of Algorithm Efficiency
Lecture 5: Asymptotic analysis of algorithms
Introduction to Algorithms Complexity Analysis
Algorithm analysis
Unit i basic concepts of algorithms
Daa unit 1
Lecture 2 data structures and algorithms
02 order of growth

What's hot (20)

PPT
chapter 1
PDF
Algorithms Lecture 1: Introduction to Algorithms
PPTX
Daa unit 5
PDF
Daa notes 1
PPTX
Algorithm analysis (All in one)
PPTX
Analysis of algorithn class 2
PDF
Daa notes 2
PPTX
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
PPT
Data Structures and Algorithm Analysis
PDF
Lecture 2 role of algorithms in computing
PDF
Theory of algorithms final
PPT
Introduction to data structures and Algorithm
PDF
Algorithm Analyzing
PDF
01 Analysis of Algorithms: Introduction
PPTX
Data Structures - Lecture 1 [introduction]
PPT
Design and analysis of Algorithm By Dr. B. J. Mohite
PPT
Data Structures- Part2 analysis tools
PPT
Introduction to design and analysis of algorithm
PPTX
Introduction to datastructure and algorithm
chapter 1
Algorithms Lecture 1: Introduction to Algorithms
Daa unit 5
Daa notes 1
Algorithm analysis (All in one)
Analysis of algorithn class 2
Daa notes 2
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
Data Structures and Algorithm Analysis
Lecture 2 role of algorithms in computing
Theory of algorithms final
Introduction to data structures and Algorithm
Algorithm Analyzing
01 Analysis of Algorithms: Introduction
Data Structures - Lecture 1 [introduction]
Design and analysis of Algorithm By Dr. B. J. Mohite
Data Structures- Part2 analysis tools
Introduction to design and analysis of algorithm
Introduction to datastructure and algorithm
Ad

Similar to Unit ii algorithm (20)

PPTX
Algorithm for the DAA agscsnak javausmagagah
PPTX
design analysis of algorithmaa unit 1.pptx
PPTX
Algorithm.pptx
PPTX
Algorithm.pptx
PDF
Performance Analysis,Time complexity, Asymptotic Notations
PPTX
DAA-Unit1.pptx
PDF
Algorithm Analysis.pdf
PPTX
2. Introduction to Algorithm.pptx
PPTX
Searching Algorithms
PPTX
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
PPTX
Algorithms & Complexity Calculation
PDF
DSA
PPTX
Design and analysis of algorithms unit1.pptx
PPTX
Introduction to algorithms
PDF
Python algorithm
PPTX
9 big o-notation
PPTX
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
PDF
Data Structure & Algorithms - Mathematical
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm for the DAA agscsnak javausmagagah
design analysis of algorithmaa unit 1.pptx
Algorithm.pptx
Algorithm.pptx
Performance Analysis,Time complexity, Asymptotic Notations
DAA-Unit1.pptx
Algorithm Analysis.pdf
2. Introduction to Algorithm.pptx
Searching Algorithms
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Algorithms & Complexity Calculation
DSA
Design and analysis of algorithms unit1.pptx
Introduction to algorithms
Python algorithm
9 big o-notation
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
Data Structure & Algorithms - Mathematical
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Ad

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
PPT on Performance Review to get promotions
PPTX
additive manufacturing of ss316l using mig welding
PPTX
web development for engineering and engineering
PDF
Digital Logic Computer Design lecture notes
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Geodesy 1.pptx...............................................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
composite construction of structures.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
CYBER-CRIMES AND SECURITY A guide to understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Foundation to blockchain - A guide to Blockchain Tech
PPT on Performance Review to get promotions
additive manufacturing of ss316l using mig welding
web development for engineering and engineering
Digital Logic Computer Design lecture notes
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
UNIT 4 Total Quality Management .pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Geodesy 1.pptx...............................................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
composite construction of structures.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx

Unit ii algorithm

  • 1. Unit - II Algorithm 1 Prepared By: Dabbal Singh Mahara
  • 2. Unit –II: Table of Contents • Concept and definition • Characteristic of algorithm • Design of algorithm • Big O notation 2
  • 3. An algorithm, named after the ninth century scholar Abu Jafar Muhammad Ibn Musu Al-Khowarizmi, is defined as follows: • An algorithm is a finite step-by-step procedure to achieve a required result. • An algorithm is a sequence of computational steps that transform the input into the output. • An algorithm is a precise specification of a sequence of instructions to be carried out in order to solve a given problem. Each instruction tells what task is to be done. There should be a finite number of instructions in an algorithm and each instruction should be executed in a finite amount of time. Algorithm 3
  • 4. • Input: A number of quantities are provided to an algorithm initially before the algorithm begins. These quantities are inputs which are processed by the algorithm. • Definiteness: Each step must be clear and unambiguous that leads to a specific action. • Effectiveness: Each step must be carried out in finite time. • Finiteness: Algorithm must terminate after finite time or steps • Output: An algorithm must have one or more output. • Correctness: Correct set of output values must be produced from the each set of inputs. For the same input data, it must always produce the same output. Characteristics of Algorithms 4
  • 5. • An algorithm can be written in a number of ways such as natural language, pseudo-code, or flowcharts. Pseudo-code is a popular way to express algorithm. • Pseudo-code is a way of expressing algorithms that uses a mixture of English phrases and indention to make the steps in the solution explicit • Pseudo-code cannot be compiled nor executed, and there are no real formatting or syntax rules. • The benefit of pseudo-code is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language and easy to convert it into programs in any language. • There is not any standard rules for writing algorithm. Writing Algorithm 5
  • 6. Example: Write an algorithm to find the largest among three different numbers entered by user. Step 1: Start Step 2: Declare variables a, b and c. Step 3: Read variables a, b and c. Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop 6
  • 7. 1. The “design” pertain to i. The description of algorithm at an abstract level by means of a pseudo language, and ii. Proof of correctness that is, the algorithm solves the given problem in all cases. 2. The “analysis” deals with performance evaluation or complexity analysis. The complexity of an algorithm is a function describing the efficiency of the algorithm in terms of the amount of data the algorithm must process. That is, algorithmic complexity is a function of problem size that refers to the rate at which required storage or consumed time grows as input size increases. There are two main complexity measures of the efficiency of an algorithm: Time Complexity and Space complexity. Analysis of algorithm in terms of efficiency allows programmers to compare the algorithms for selecting appropriate one. Design and Analysis of Algorithm 7
  • 8. Time Complexity 8 • Time complexity is a function describing the amount of time an algorithm takes in terms of the amount of input to the algorithm. • That is, it is a function that refers the rate at which consumed time increases as input size increases. • To simplify the analysis, the time for the operations that is constant independent of input size is ignored. Simplified analysis can be based on: • Number of arithmetic operation performed • Number of comparisons made • Number of times through a loop • Number of array elements are accessed etc. • Although the running time of an implementation of the algorithm would depend upon the speed of the computer, programming language, compiler etc, these technical issues are ignored. Only how running time is increasing with increasing input size is considered in analysis. • When analyzing algorithm it depends upon the input data, there are three cases: • Best case: • Average case: • Worst case: • best, worst, and average cases of a given algorithm express what the resource usage is at least, at most and on average, respectively. Usually the resource being considered is running time, i.e. time complexity, but it could also be memory or other resources.
  • 9. 9 #include <stdio.h> // Linearly search x in arr[]. // If x is present then return the index, // otherwise return -1 int search(int arr[], int n, int x) { int i; for (i=0; i<n; i++) { if (arr[i] == x) return i; } return -1; } /* Driver program to test above functions*/ int main() { int arr[] = {1, 10, 30, 15}; int x = 30; int n = sizeof(arr)/sizeof(arr[0]); printf("%d is present at index %d", x, search(arr, n, x)); getchar(); return 0; } Let us consider the following implementation of Linear Search. For Linear Search • The worst case happens when the element to be searched (x in the above code) is not present in the array. When x is not present, the search() functions compares it with all the elements of arr[] one by one. • Let us assume that all cases are uniformly distributed (including the case of x not being present in array). So we sum all the cases and divide the sum by (n+1). • The best case occurs when x is present at the first location. The number of operations in the best case is constant (not dependent on n).
  • 10. Space Complexity 10 Analysis of space complexity of an algorithm is the amount of memory it needs to run to completion. It is the rate at which required storage space grows as a function of input size. The space needed by a program consists of following components: • Instruction Space: space for code • Data Space: space for variables, constants • Environment stack space: return address, local variables in called function.Example: Algorithm Sum(a,n) { s:=0.0; for i:=1 to n do s:=s+a[i]; return s; } The space needed by n is one word, since it is of type integer. The space needed by a is the space needed by variables of type array of floating point numbers. This is at least n words, since a must be large enough to hold the n elements to be summed. So, Ssum(n) >= (n+3), n for a[], 1 for each n, I and s).
  • 11. Asymptotic Analysis 11 Big Oh Notation • Big Oh is a characteristic scheme that measures properties of algorithm complexity performance and/or memory requirements by eliminating constant factors. • Big Oh notation is the formal method of expressing the upper bound of an algorithm's running time. It's a measure of the longest amount of time it could possibly take for the algorithm to complete. • With big O notation we express the runtime in terms of—how quickly it grows relative to the input, as the input gets arbitrarily large. • It's how we compare the efficiency of different algorithms to a problem. • Properties of Big O: − Measuring the amount of work as it varies with the size of the data affected − Predicting the expected overall performance of an algorithm − Generally measured relative to other algorithms to handle the same problem • Big O has following limitations: − It ignores potential of constant factors in the algorithm. − It does not try to improve algorithm, only gives the complexity. • The exact time of an algorithm will depend on the implementation of algorithm, amount input data, programming language, CPU speed etc. • There is a proportionality approach to measure the time complexity in terms of relationship between input size and number of key operations of computational process. This type of analysis is known as asymptotic analysis. • For asymptotic analysis we use different notations:
  • 12. 12 Big Oh (O) notation When we have only asymptotic upper bound then we use O notation. Formal definition Let f and g be any two functions defined over set of positive integers. A function f(n) is big oh of g(n) ), denoted as f(n)=O(g(n)), if there exists two positive constants c and n0 such that for all n >= n0, f(n) <= c*g(n). • O(1) is used to denote constants. • Example: f(n)=5n3+3n2+4 and g(n) =12n3 Then, is f(n) = O(n3)? n F(n) g(n) 1 12 12 True 2 56 96 True 3 166 324 True 4 372 768 True Therefore, for all n >=n0=1, c = 12, f(n) <= c*g(n) => f(n) = O(g(n)). • Example: 2 If f(x)= 5x2+4x + 2 find big oh(O) of f(x). Here, f(x)= 5x2+4x + 3 <= 5x2+4x2+ 2x2 = 11x2 , for all x>=1 f(x) <= c * g(x), where c =11, g(x) = x2 and x0 = 1. Therefore, f(x) = O(x2 ).
  • 13. 13 Big Omega ( Ω ) notation Big omega notation gives asymptotic lower bound. Formal definition Let f and g be any two functions defined over set of positive integers. A function f(n) is big Omega of g(n) ), denoted as f(n)= Ω (g(n)), if there exists two positive constants c and n0 such that for all n >= n0, f(n) >= c*g(n). The above relation says that g(x) is a lower bound of f(x). Example: If f(n)= 3n2 +4n + 7, find big omega of f(n). Here, f(n)= 3n2 +4n + 7 >= 3n2 for all n>= 1. i.e. f(n) >= c * g(n), where c = 3, n0=1 and g(n) =n2 . Therefore, f(n) = Ω (g(n).
  • 14. 14 Big Theta ( Θ ) notation When we need asymptotically tight bound then we use notation. Formal definition Let f and g be any two functions defined over set of positive integers. A function f(n) is big Theta of g(n) ), denoted as f(n)= Θ (g(n)), if there exists three positive constants c1, c2 and n0 such that for all n >= n0, c1*g(n) <= f(n) <= c2*g(n). The above relation says that f(x) is order of g(x) Example: f(n) = 3n2 + 4n + 7 g(n) = n2 , then prove that f(n) = (g(n)). Proof: let us choose c1, c2 and n0 values as 14, 1 and 1 respectively then we can have, f(n) <= c1*g(n), n>=n0 as 3n2 + 4n + 7 <= 14*n2 , and f(n) >= c2*g(n), n>=n0 as 3n2 + 4n + 7 >= 1*n2 for all n >= 1(in both cases). So c2*g(n) <= f(n) <= c1*g(n) is trivial. Hence f(n) = Θ(g(n)).
  • 15. 15
  • 16. 16
  • 17. 17