Big-O notation.

Slides:



Advertisements
Similar presentations
the fourth iteration of this loop is shown here
Advertisements

CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
Introduction to Analysis of Algorithms
Cmpt-225 Algorithm Efficiency.
Elementary Data Structures and Algorithms
Algorithm Analysis (Big O)
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
Program Performance & Asymptotic Notations CSE, POSTECH.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
Lecture 2 Computational Complexity
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Asymptotic Notation (O, Ω, )
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Algorithms & Flowchart
MS 101: Algorithms Instructor Neelima Gupta
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Time Complexity of Algorithms (Asymptotic Notations)
Asymptotic Notations By Er. Devdutt Baresary. Introduction In mathematics, computer science, and related fields, big O notation describes the limiting.
Algorithm Analysis (Big O)
Algorithms Lecture #05 Uzair Ishtiaq. Asymptotic Notation.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
(Complexity) Analysis of Algorithms Algorithm Input Output 1Analysis of Algorithms.
Algorithm Analysis 1.
Complexity Analysis (Part I)
Analysis of Algorithms
Mathematical Foundation
Introduction to Analysis of Algorithms
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Introduction to Analysis of Algorithms
Introduction to Algorithms
Introduction to Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Lecture – 2 on Data structures
Lecture 3 of Computer Science II
Analysis of Algorithms
Introduction to Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Algorithm Analysis (not included in any exams!)
Objective of This Course
GC 211:Data Structures Algorithm Analysis Tools
Analysis of Algorithms
Analysis of Algorithms
Analysys & Complexity of Algorithms
Advanced Analysis of Algorithms
Chapter 2.
Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Fundamentals of the Analysis of Algorithm Efficiency
Searching, Sorting, and Asymptotic Complexity
Asst. Dr.Surasak Mungsing
Revision of C++.
Performance Evaluation
Analysis of Algorithms
Math/CSE 1019N: Discrete Mathematics for Computer Science Winter 2007
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
The Efficiency of Algorithms
Complexity Analysis (Part I)
Algorithm Efficiency and Sorting
Analysis of Algorithms
Complexity Analysis (Part I)
Presentation transcript:

big-O notation

History Big O notation (with a capital letter O, not a zero), also called Landau's symbol, is a symbolism used in complexity theory, computer science, and mathematics to describe the asymptotic behavior of functions. Basically, it tells you how fast a function grows or declines.

Definition Definition: A theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n, which is usually the number of items. Informally, saying some equation f(n) = O(g(n)) means it is less than some constant multiple of g(n). The notation is read, "f of n is big oh of g of n".

Efficiency of algorithm How efficient is an algorithm or piece of code? Efficiency covers lots of resources, including: CPU (time) usage memory usage disk usage network usage All are important but we will mostly talk about time complexity (CPU usage)

Performance vs. Complexity Be careful to differentiate between: Performance: how much time/memory/disk/... is actually used when a program is run. This depends on the machine, compiler, etc. as well as the code. Complexity: how do the resource requirements of a program or algorithm scale, i.e., what happens as the size of the problem being solved gets larger? Complexity affects performance but not the other way around.

Time dependence The time required by a function/procedure is proportional to the number of "basic operations" that it performs. Here are some examples of basic operations: one arithmetic operation (e.g., +, *). one assignment (e.g. x := 0) one test (e.g., x = 0) one read (of a primitive type: integer, float, character, boolean) one write (of a primitive type: integer, float, character, boolean)

problem size/input size Some functions/procedures perform the same number of operations every time they are called. Other functions/ procedures may perform different numbers of operations, depending on the value of a parameter. For example, in the Bubble Sort algorithm, the number of elements in the array, determines the number of operations performed by the algorithm. This parameter (number of elements) is called the problem size/ input size.

big-O notation will not find the complexity of the function/ procedure/ algorithm/ program, it will try to give the exact number of operations that are being performed. Instead, it is interested in the relation of the number of operations to the problem size.

Formal definition The notation is read, "f of n is big oh of g of n". Formal Definition: f(n) = O(g(n)) means there are positive constants c and k, such that 0 ≤ f(n) ≤ cg(n) for all n ≥ k. The values of c and k must be fixed for the function f and must not depend on n. Also known as O. Typically, big-O notation is interested in the worst case: what is the maximum number of operations that might be performed for a given problem size.

For example, inserting an element into an array, we have to move the current element and all of the elements that come after it one place to the right in the array. In the worst case, inserting at the beginning of the array, all of the elements in the array must be moved. Therefore, in the worst case, the time for insertion is proportional to the number of elements in the array, and we say that the worst-case time for the insertion operation is linear in the number of elements in the array. For a linear-time algorithm, if the problem size doubles, the number of operations also doubles.