Lesson Objectives Aims Understand the following: The big O notation.

Slides:



Advertisements
Similar presentations
Order of complexity. Consider four algorithms 1.The naïve way of adding the numbers up to n 2.The smart way of adding the numbers up to n 3.A binary search.
Advertisements

Growth-rate Functions
College of Information Technology & Design
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
Computational Complexity 1. Time Complexity 2. Space Complexity.
Cmpt-225 Algorithm Efficiency.
Real-Valued Functions of a Real Variable and Their Graphs
Algorithm Efficiency and Sorting Bina Ramamurthy CSE116A,B.
1 Section 2.3 Complexity of Algorithms. 2 Computational Complexity Measure of algorithm efficiency in terms of: –Time: how long it takes computer to solve.
Analysis of Algorithms CPS212 Gordon College. Measuring the efficiency of algorithms There are 2 algorithms: algo1 and algo2 that produce the same results.
Algorithm Analysis (Big O)
1 MT258 Computer Programming and Problem Solving Unit 9.
Program Performance & Asymptotic Notations CSE, POSTECH.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
CS 2430 Day 28. Announcements We will have class in ULR 111 on Monday Exam 2 next Friday (sample exam will be distributed next week)
1.2. Comparing Algorithms. Learning outcomes Understand that algorithms can be compared by expressing their complexity as a function relative to the size.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Chapter 2 Array Data Structure Winter Array The Array is the most commonly used Data Storage Structure. It’s built into most Programming languages.
Big Oh Algorithms are compared to each other by expressing their efficiency in big-oh notation Big O notation is used in Computer Science to describe the.
Growth of Functions. Asymptotic Analysis for Algorithms T(n) = the maximum number of steps taken by an algorithm for any input of size n (worst-case runtime)
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
3.3 Complexity of Algorithms
Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
CS 2430 Day 30. Announcements Quiz #5: 4/19 Agenda Big O Searching –Linear search.
Searching Topics Sequential Search Binary Search.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
Copyright © 2009 Curt Hill Look Ups A Recurring Theme.
Concepts of Algorithms CSC-244 Unit 3 and 4 Algorithm Growth Rates Shahid Iqbal Lone Computer College Qassim University K.S.A.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Section 1: Problem solving AQA Computing A2 © Nelson Thornes 2009 Examples of problems with different time complexities Section 1.2: Comparing algorithms.
Algorithm Analysis 1.
Algorithmic Efficency
U1A L6 Linear, Quadratic & Polynomial Inequalities
Introduction to Analysis of Algorithms
Introduction to complexity
Computer Science 112 Fundamentals of Programming II
Big O notation Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case.
Introduction to Analysis of Algorithms
Big-O notation.
CSE 373: Data Structures and Algorithms Pep Talk; Algorithm Analysis
Introduction to Algorithms
Big O: Make it Simple Determine how complex the algorithm is, in relative to the size of the problem (e.g: List to be sorted) 'O' Stands for 'Order' -
Algorithm Efficiency Algorithm efficiency
Big-Oh and Execution Time: A Review
Building Java Programs
Algorithm design and Analysis
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
ITEC 2620M Introduction to Data Structures
Big O Notation.
CSC 205 Java Programming II
Comparing Algorithms Unit 1.2.
Algorithm Analysis Bina Ramamurthy CSE116A,B.
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
GC 211:Data Structures Algorithm Analysis Tools
CSE 373 Data Structures Lecture 5
Searching, Sorting, and Asymptotic Complexity
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Mathematical Background 2
Time Complexity Lecture 15 Mon, Feb 27, 2006.
CMPT 225 Lecture 6 – Review of Complexity Analysis using the Big O notation + Comparing List ADT class implementations.
Data Structures & Programming
Presentation transcript:

Lesson Objectives Aims Understand the following: The big O notation

Big O Notation Big O is the “Order” of magnitude for an algorithm What does that mean? It’s an estimate of the time an algorithm will take for a given data set. It can be used to measure its efficiency

Big O Represented as O(function of N) N = the size of the input data set O = generally the worst case scenario

Big O Algorithms, and indeed algorithmic complexity, are divided in to types: Constant Linear Polynomial Exponential Logarithmic

Big O notation is used to show: Key Points Big O notation is used to show: The time algorithms take Or the space they need increases as the size of the data set they operate on increases

Calculating big O We can express the complexity of an algorithm in an equation We then simplify the equation to express the term in one of the big O forms (linear, exponential etc)

Example 7n3 + n2 + 4n +1 as n increases - what happens to the different terms of this equation? The larger n gets, the less an impact n2 + 4n +1 has on the total compared to n3

To calculate Big O for a given expression: Remove all terms except the one with the largest exponent Remove any constant factors

Questions

1 = O(n4) = Polynomial 2 = O(n) = linear complexity

Questions

3 = O(n2) = Quadratic 4 = O(10) = Constant

Constant complexity O(1) O(1) Algorithms take the same time to run regardless of the size of the dataset Example: push an item to the stack

Linear complexity O(n) The time taken to solve an O(n) algorithms increases at the same rate as the input size If the input dataset doubles in size, the time taken doubles Example: find an element using linear search

Polynomial complexity O(nk) where k is a positive integer The complexity varies depending on the power of the function. If k = 0: n^0 = 1 constant complexity If k = 1 linear complexity If K = 2 quadratic complexity If K = 3 cubic complexity

Quadratic complexity O(n2) Time taken rapidly increases with the size of the data set example: bubble sort

Exponential complexity Instead of O(nk), it is O(kn) Time taken rises at a much faster rate than polynomial complexity The complexity is to the power of the number of elements Does not scale well

Logarithmic Complexity O(log n) Start off expensive As the data set grows, the complexity decreases and eventually levels out A good situation to be in E.g. Binary Search.

Comparison

Reading https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/ https://justin.abrah.ms/computer-science/big-o-notation-explained.html Shows in the context of code

Review/Success Criteria You should know: The