SlideShare uma empresa Scribd logo
1 de 29
Data Structures I (CPCS-204) 
Week # 2: Algorithm Analysis tools
Algorithm Analysis: Motivation 
 A problem can be solved in many different ways 
 Single problem, many algorithms 
 Which of the several algorithms should I 
choose? 
 We use algorithm analysis to answer this question 
o Writing a working program is not good enough 
o The program may be inefficient! 
o If the program runs on a large data set, then the running time 
becomes an issue
What is algorithm analysis? 
 A methodology to predict the resources that the 
algorithm requires 
 Computer memory 
 Computational time 
 We’ll focus on computational time 
 It does not mean memory is not important 
 Generally, there is a trade-off between the two factors 
o Space-time trade-off is a common term
How to analyse algorithms? 
 Experimental Approach 
 Implement algorithms as programs and run them on 
computers 
 Not a good approach, though! 
o Results only for a limited set of test inputs 
o Difficult comparisons due to the experiment environments 
(need the same computers, same operating systems, etc.) 
o Full implementation and execution of an algorithm 
 We need an approach which allows us to avoid 
experimental study
How to analyse algorithms? 
 Theoretical Approach 
 General methodology for analysing the running time 
o Considers all possible inputs 
o Evaluates algorithms in a way that is independent from the 
hardware and software environments 
o Analyses an algorithm without implementing it 
 Count only primitive operations used in an algorithm 
 Associate each algorithm with a function f(n) that 
characterises the running time of the algorithm as a 
function of the input size n 
o A good approximation of the total number of primitive 
operations
Primitive Operations 
 Basic computations performed by an algorithm 
 Each operation corresponding to a low-level 
instruction with a constant execution time 
 Largely independent from the programming 
language 
 Examples 
 Evaluating an expression (x + y) 
 Assigning a value to a variable (x ←5) 
 Comparing two numbers (x < y) 
 Indexing into an array (A[i]) 
 Calling a method (mycalculator.sum()) 
 Returning from a method (return result)
Counting Primitive Operations 
 Total number of primitive operations executed 
 is the running time of an algorithms 
 is a function of the input size 
 Example 
Algorithm ArrayMax(A, n) # operations 
currentMax ←A[0] 2: (1 +1) 
for i←1;i<n; i←i+1 do 3n-1: (1 + n+2(n- 1)) 
if A[i]>currentMax then 2(n − 1) 
currentMax ←A[i] 2(n − 1) 
endif 
endfor 
return currentMax 1 
Total: 7n − 2
Algorithm efficiency: growth rate 
 An algorithm’s time requirements can be 
expressed as a function of (problem) input size 
 Problem size depends on the particular problem: 
 For a search problem, the problem size is the 
number of elements in the search space 
 For a sorting problem, the problem size is the 
number of elements in the given list 
 How quickly the time of an algorithm grows as a 
function of problem size -- this is often called an 
algorithm’s growth rate
Algorithm growth rate 
Which algorithm is the most efficient? [The one with 
the growth rate Log N.]
Algorithmic time complexity 
 Rather than counting the exact number of 
primitive operations, we approximate the 
runtime of an algorithm as a function of data 
size – time complexity 
 Algorithms A, B, C and D (previous slide) 
belong to different complexity classes 
 We’ll not cover complexity classes in detail – 
they will be covered in Algorithm Analysis 
course, in a later semester 
 We’ll briefly discuss seven basic functions 
which are often used in complexity analysis
Seven basic function 
1. Constant function f(n) = c 
2. Linear function f(n) = n 
3. Quadratic function f(n) = n2 
4. Cubic function f(n) = n3 
5. Log function f(n) = log n 
6. Log linear function f(n) = n log n 
7. Exponential function f(n) = bn
Constant function 
 For a given argument/variable n, the function 
always returns a constant value 
 It is independent of variable n 
 It is commonly used to approximate the total 
number of primitive operations in an algorithm 
 Most common constant function is g(n) = 1 
 Any constant value c can be expressed as 
constant function f(n) = c.g(1)
Linear function 
 For a given argument/variable n, the function 
always returns n 
 This function arises in algorithm analysis any 
time we have to do a single basic operation over 
each of n elements 
 For example, finding min/max value in a list 
of values 
 Time complexity of linear/sequential search 
algorithm is linear
Quadratic function 
 For a given argument/variable n, the function 
always returns square of n 
 This function arises in algorithm analysis any 
time we use nested loops 
 The outer loop performs primitive operations in 
linear time; for each iteration, the inner loop also 
perform primitive operations in linear time 
 For example, sorting an array in 
ascending/descending order using Bubble Sort 
(more later on) 
 Time complexity of most algorithms is quadratic
Cubic function 
 For a given argument/variable n, the function 
always returns n x n x n 
 This function is very rarely used in algorithm 
analysis 
 Rather, a more general class “polynomial” is 
often used 
o f(n) = a0 + a1n + a2n2 + a3n3 + … + adnd
Logarithmic function 
 For a given argument/variable n, the function 
always returns logarithmic value of n 
 Generally, it is written as f(n) = logbn, where b 
is base which is often 2 
 This function is also very common in 
algorithm analysis 
 We normally approximate the logbn to a value 
x. x is number of times n is divided by b until 
the division results in a number less than or 
equal to 1 
 log327 is 3, since 27/3/3/3 = 1. 
 log464 is 3, since 64/4/4/4 = 1 
 log212 is 4, since 12/2/2/2/2 = 0.75 ≤ 1
Log linear function 
 For a given argument/variable n, the function 
always returns n log n 
 Generally, it is written as f(n) = n logbn, where 
b is base which is often 2 
 This function is also common in algorithm 
analysis 
 Growth rate of log linear function is faster as 
compared to linear and log functions
Exponential function 
 For a given argument/variable n, the function 
always returns bn, where b is base and n is 
power (exponent) 
 This function is also common in algorithm 
analysis 
 Growth rate of exponential function is faster 
than all other functions
Algorithmic runtime 
 Worst-case running time 
 measures the maximum number of primitive operations 
executed 
 The worst case can occur fairly often 
o e.g. in searching a database for a particular piece of information 
 Best-case running time 
 measures the minimum number of primitive operations 
executed 
o Finding a value in a list, where the value is at the first position 
o Sorting a list of values, where values are already in desired order 
 Average-case running time 
 the efficiency averaged on all possible inputs 
 maybe difficult to define what “average” means
Complexity classes 
 Suppose the execution time of algorithm A is a 
quadratic function of n (i.e. an2 + bn + c) 
 Suppose the execution time of algorithm B is a 
linear function of n (i.e. an + b) 
 Suppose the execution time of algorithm C is a 
an exponential function of n (i.e. a2n) 
 For large problems higher order terms dominate 
the rest 
 These three algorithms belong to three different 
“complexity classes”
Big-O and function growth rate 
 We use a convention O-notation (also called 
Big-Oh) to represent different complexity classes 
 The statement “f(n) is O(g(n))” means that the 
growth rate of f(n) is no more than the growth 
rate of g(n) 
 g(n) is an upper bound on f(n), i.e. maximum 
number of primitive operations 
 We can use the big-O notation to rank functions 
according to their growth rate
22 
Big-O: functions ranking 
• O(1) constant time 
• O(log n) log time 
• O(n) linear time 
• O(n log n) log linear time 
• O(n2) quadratic time 
• O(n3) cubic time 
• O(2n) exponential time 
BETTER 
WORSE
Simplifications 
 Keep just one term 
 the fastest growing term (dominates the runtime) 
 No constant coefficients are kept 
 Constant coefficients affected by machines, 
languages, etc 
 Asymptotic behavior (as n gets large) is determined 
entirely by the dominating term 
 Example: T(n) = 10 n3 + n2 + 40n + 800 
o If n = 1,000, then T(n) = 10,001,040,800 
o error is 0.01% if we drop all but the n3 (the 
dominating) term
Big Oh: some examples 
 n3 – 3n = O(n3) 
 1 + 4n = O(n) 
 7n2 + 10n + 3 = O(n2) 
 2n + 10n + 3 = O(2n)
Big O: more examples 
 f(n) = 7n – 2; 7n - 2 is O(n) 
? Find c > 0 and n0 ≥ 1 such that 7n-2 ≤ c•n for n ≥ n0 
This is true for c = 7 and n0 = 1 
at n = 1, 7-2 ≤ 7; at n = 2, 14 – 2 ≤ 14, and so on 
 f(n) = 3 log n + 5; 3 log n + 5 is O(log n) 
? Find c > 0 and n0 ≥ 1 such that 3 log n + 5 ≤ c•log n for n ≥ n0 
This is true for c = 8 and n0 = 2
Interpreting Big-O 
 f(n) is less than or equal to g(n) up to a constant 
factor and in the asymptotic sense as n 
approaching infinity (n→∞) 
 The big-O notation gives an upper bound on the 
growth rate of a function 
 The big-O notation allows us to 
 ignore constant factors and lower order terms 
 focus on the main components of a function that 
effect the growth 
 ignoring constants and lower order terms does not 
change the “complexity class” – it’s very important to 
remember
Asymptotic algorithm analysis 
 Determines the running time in big-O notation 
 Asymptotic analysis 
 find the worst-case number of primitives 
 operations executed as a function of the input size 
 express this function with big-O notation 
 Example: 
 algorithm arrayMax executes at most 7n − 2primitive 
operations 
 algorithm arrayMax runs in O(n) time
Practice 
 Express the following functions in terms of Big-O 
notation (a, b and c are constants) 
1. f(n) = an2 + bn + c 
2. f(n) = 2n + n log n + c 
3. f(n) = n log n + b log n + c
Outlook 
Next week, we’ll discuss arrays and searching algorithms

Mais conteúdo relacionado

Mais procurados

Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1Manoj Patil
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Eelco Visser
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysisRicha Sharma
 
Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...
Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...
Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...Mikhail Kurnosov
 
Lecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesLecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesRajesh K Shukla
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism JavaM. Raihan
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
ANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.pptANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.pptDaveCalapis3
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer Ashim Lamichhane
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithmrajkumar1631010038
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSARASWATHI S
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 

Mais procurados (20)

Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...
Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...
Лекция 2: Оптимизация ветвлений и циклов (Branch prediction and loops optimiz...
 
Lisp
LispLisp
Lisp
 
Lecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesLecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its Properties
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
ANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.pptANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 

Destaque

Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesAbdullah Al-hazmy
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedAbdullah Al-hazmy
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 
Data Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsData Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsAbdullah Al-hazmy
 
9781111530532 ppt ch14
9781111530532 ppt ch149781111530532 ppt ch14
9781111530532 ppt ch14Terry Yoast
 
9781285852744 ppt ch16
9781285852744 ppt ch169781285852744 ppt ch16
9781285852744 ppt ch16Terry Yoast
 
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...Amazon Web Services Korea
 
Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in PracticeGanesh Samarthyam
 
AWS ECS Quick Introduction
AWS ECS Quick IntroductionAWS ECS Quick Introduction
AWS ECS Quick IntroductionVinothini Raju
 
Web Database
Web DatabaseWeb Database
Web Databaseidroos7
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8Garth Gilmour
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked listsAbdullah Al-hazmy
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - PraticalsFahad Shaikh
 
Java 8 Support at the JVM Level
Java 8 Support at the JVM LevelJava 8 Support at the JVM Level
Java 8 Support at the JVM LevelNikita Lipsky
 
Building Digital Transaction Systems in the new Banking World
Building Digital Transaction Systems in the new Banking WorldBuilding Digital Transaction Systems in the new Banking World
Building Digital Transaction Systems in the new Banking WorldRamit Surana
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 

Destaque (20)

Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queues
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplified
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Data Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsData Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithms
 
9781111530532 ppt ch14
9781111530532 ppt ch149781111530532 ppt ch14
9781111530532 ppt ch14
 
Chap01
Chap01Chap01
Chap01
 
9781285852744 ppt ch16
9781285852744 ppt ch169781285852744 ppt ch16
9781285852744 ppt ch16
 
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
 
Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in Practice
 
AWS ECS Quick Introduction
AWS ECS Quick IntroductionAWS ECS Quick Introduction
AWS ECS Quick Introduction
 
Web Database
Web DatabaseWeb Database
Web Database
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 
Java 8 Support at the JVM Level
Java 8 Support at the JVM LevelJava 8 Support at the JVM Level
Java 8 Support at the JVM Level
 
Building Digital Transaction Systems in the new Banking World
Building Digital Transaction Systems in the new Banking WorldBuilding Digital Transaction Systems in the new Banking World
Building Digital Transaction Systems in the new Banking World
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 

Semelhante a Data Structures- Part2 analysis tools

TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...TechVision8
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusNANDINI SHARMA
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptxNishaS88
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfMemMem25
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 
Data Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdfData Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdfRameshaFernando2
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptxEnosSalar
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithmssangeetha s
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.Tariq Khan
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdfishan743441
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 

Semelhante a Data Structures- Part2 analysis tools (20)

Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
Lec1
Lec1Lec1
Lec1
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Data Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdfData Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdf
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptx
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithms
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 

Último

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Último (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Data Structures- Part2 analysis tools

  • 1. Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools
  • 2. Algorithm Analysis: Motivation  A problem can be solved in many different ways  Single problem, many algorithms  Which of the several algorithms should I choose?  We use algorithm analysis to answer this question o Writing a working program is not good enough o The program may be inefficient! o If the program runs on a large data set, then the running time becomes an issue
  • 3. What is algorithm analysis?  A methodology to predict the resources that the algorithm requires  Computer memory  Computational time  We’ll focus on computational time  It does not mean memory is not important  Generally, there is a trade-off between the two factors o Space-time trade-off is a common term
  • 4. How to analyse algorithms?  Experimental Approach  Implement algorithms as programs and run them on computers  Not a good approach, though! o Results only for a limited set of test inputs o Difficult comparisons due to the experiment environments (need the same computers, same operating systems, etc.) o Full implementation and execution of an algorithm  We need an approach which allows us to avoid experimental study
  • 5. How to analyse algorithms?  Theoretical Approach  General methodology for analysing the running time o Considers all possible inputs o Evaluates algorithms in a way that is independent from the hardware and software environments o Analyses an algorithm without implementing it  Count only primitive operations used in an algorithm  Associate each algorithm with a function f(n) that characterises the running time of the algorithm as a function of the input size n o A good approximation of the total number of primitive operations
  • 6. Primitive Operations  Basic computations performed by an algorithm  Each operation corresponding to a low-level instruction with a constant execution time  Largely independent from the programming language  Examples  Evaluating an expression (x + y)  Assigning a value to a variable (x ←5)  Comparing two numbers (x < y)  Indexing into an array (A[i])  Calling a method (mycalculator.sum())  Returning from a method (return result)
  • 7. Counting Primitive Operations  Total number of primitive operations executed  is the running time of an algorithms  is a function of the input size  Example Algorithm ArrayMax(A, n) # operations currentMax ←A[0] 2: (1 +1) for i←1;i<n; i←i+1 do 3n-1: (1 + n+2(n- 1)) if A[i]>currentMax then 2(n − 1) currentMax ←A[i] 2(n − 1) endif endfor return currentMax 1 Total: 7n − 2
  • 8. Algorithm efficiency: growth rate  An algorithm’s time requirements can be expressed as a function of (problem) input size  Problem size depends on the particular problem:  For a search problem, the problem size is the number of elements in the search space  For a sorting problem, the problem size is the number of elements in the given list  How quickly the time of an algorithm grows as a function of problem size -- this is often called an algorithm’s growth rate
  • 9. Algorithm growth rate Which algorithm is the most efficient? [The one with the growth rate Log N.]
  • 10. Algorithmic time complexity  Rather than counting the exact number of primitive operations, we approximate the runtime of an algorithm as a function of data size – time complexity  Algorithms A, B, C and D (previous slide) belong to different complexity classes  We’ll not cover complexity classes in detail – they will be covered in Algorithm Analysis course, in a later semester  We’ll briefly discuss seven basic functions which are often used in complexity analysis
  • 11. Seven basic function 1. Constant function f(n) = c 2. Linear function f(n) = n 3. Quadratic function f(n) = n2 4. Cubic function f(n) = n3 5. Log function f(n) = log n 6. Log linear function f(n) = n log n 7. Exponential function f(n) = bn
  • 12. Constant function  For a given argument/variable n, the function always returns a constant value  It is independent of variable n  It is commonly used to approximate the total number of primitive operations in an algorithm  Most common constant function is g(n) = 1  Any constant value c can be expressed as constant function f(n) = c.g(1)
  • 13. Linear function  For a given argument/variable n, the function always returns n  This function arises in algorithm analysis any time we have to do a single basic operation over each of n elements  For example, finding min/max value in a list of values  Time complexity of linear/sequential search algorithm is linear
  • 14. Quadratic function  For a given argument/variable n, the function always returns square of n  This function arises in algorithm analysis any time we use nested loops  The outer loop performs primitive operations in linear time; for each iteration, the inner loop also perform primitive operations in linear time  For example, sorting an array in ascending/descending order using Bubble Sort (more later on)  Time complexity of most algorithms is quadratic
  • 15. Cubic function  For a given argument/variable n, the function always returns n x n x n  This function is very rarely used in algorithm analysis  Rather, a more general class “polynomial” is often used o f(n) = a0 + a1n + a2n2 + a3n3 + … + adnd
  • 16. Logarithmic function  For a given argument/variable n, the function always returns logarithmic value of n  Generally, it is written as f(n) = logbn, where b is base which is often 2  This function is also very common in algorithm analysis  We normally approximate the logbn to a value x. x is number of times n is divided by b until the division results in a number less than or equal to 1  log327 is 3, since 27/3/3/3 = 1.  log464 is 3, since 64/4/4/4 = 1  log212 is 4, since 12/2/2/2/2 = 0.75 ≤ 1
  • 17. Log linear function  For a given argument/variable n, the function always returns n log n  Generally, it is written as f(n) = n logbn, where b is base which is often 2  This function is also common in algorithm analysis  Growth rate of log linear function is faster as compared to linear and log functions
  • 18. Exponential function  For a given argument/variable n, the function always returns bn, where b is base and n is power (exponent)  This function is also common in algorithm analysis  Growth rate of exponential function is faster than all other functions
  • 19. Algorithmic runtime  Worst-case running time  measures the maximum number of primitive operations executed  The worst case can occur fairly often o e.g. in searching a database for a particular piece of information  Best-case running time  measures the minimum number of primitive operations executed o Finding a value in a list, where the value is at the first position o Sorting a list of values, where values are already in desired order  Average-case running time  the efficiency averaged on all possible inputs  maybe difficult to define what “average” means
  • 20. Complexity classes  Suppose the execution time of algorithm A is a quadratic function of n (i.e. an2 + bn + c)  Suppose the execution time of algorithm B is a linear function of n (i.e. an + b)  Suppose the execution time of algorithm C is a an exponential function of n (i.e. a2n)  For large problems higher order terms dominate the rest  These three algorithms belong to three different “complexity classes”
  • 21. Big-O and function growth rate  We use a convention O-notation (also called Big-Oh) to represent different complexity classes  The statement “f(n) is O(g(n))” means that the growth rate of f(n) is no more than the growth rate of g(n)  g(n) is an upper bound on f(n), i.e. maximum number of primitive operations  We can use the big-O notation to rank functions according to their growth rate
  • 22. 22 Big-O: functions ranking • O(1) constant time • O(log n) log time • O(n) linear time • O(n log n) log linear time • O(n2) quadratic time • O(n3) cubic time • O(2n) exponential time BETTER WORSE
  • 23. Simplifications  Keep just one term  the fastest growing term (dominates the runtime)  No constant coefficients are kept  Constant coefficients affected by machines, languages, etc  Asymptotic behavior (as n gets large) is determined entirely by the dominating term  Example: T(n) = 10 n3 + n2 + 40n + 800 o If n = 1,000, then T(n) = 10,001,040,800 o error is 0.01% if we drop all but the n3 (the dominating) term
  • 24. Big Oh: some examples  n3 – 3n = O(n3)  1 + 4n = O(n)  7n2 + 10n + 3 = O(n2)  2n + 10n + 3 = O(2n)
  • 25. Big O: more examples  f(n) = 7n – 2; 7n - 2 is O(n) ? Find c > 0 and n0 ≥ 1 such that 7n-2 ≤ c•n for n ≥ n0 This is true for c = 7 and n0 = 1 at n = 1, 7-2 ≤ 7; at n = 2, 14 – 2 ≤ 14, and so on  f(n) = 3 log n + 5; 3 log n + 5 is O(log n) ? Find c > 0 and n0 ≥ 1 such that 3 log n + 5 ≤ c•log n for n ≥ n0 This is true for c = 8 and n0 = 2
  • 26. Interpreting Big-O  f(n) is less than or equal to g(n) up to a constant factor and in the asymptotic sense as n approaching infinity (n→∞)  The big-O notation gives an upper bound on the growth rate of a function  The big-O notation allows us to  ignore constant factors and lower order terms  focus on the main components of a function that effect the growth  ignoring constants and lower order terms does not change the “complexity class” – it’s very important to remember
  • 27. Asymptotic algorithm analysis  Determines the running time in big-O notation  Asymptotic analysis  find the worst-case number of primitives  operations executed as a function of the input size  express this function with big-O notation  Example:  algorithm arrayMax executes at most 7n − 2primitive operations  algorithm arrayMax runs in O(n) time
  • 28. Practice  Express the following functions in terms of Big-O notation (a, b and c are constants) 1. f(n) = an2 + bn + c 2. f(n) = 2n + n log n + c 3. f(n) = n log n + b log n + c
  • 29. Outlook Next week, we’ll discuss arrays and searching algorithms