Computational Complexity 1. Time Complexity 2. Space Complexity.

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
HST 952 Computing for Biomedical Scientists Lecture 10.
Fundamentals of Python: From First Programs Through Data Structures
I Advanced Algorithms Analysis. What is Algorithm?  A computer algorithm is a detailed step-by-step method for solving a problem by using a computer.
What is an Algorithm? (And how do we analyze one?)
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Complexity Analysis (Part I)
Concept of Basic Time Complexity Problem size (Input size) Time complexity analysis.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithms CPS212 Gordon College. Measuring the efficiency of algorithms There are 2 algorithms: algo1 and algo2 that produce the same results.
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
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
Mon 29 Sep 2014Lecture 4 1. Running Time Performance analysis Techniques until now: Experimental Cost models counting execution of operations or lines.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
{ 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)
Lecture 2 Computational Complexity
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
Complexity of algorithms Algorithms can be classified by the amount of time they need to complete compared to their input size. There is a wide variety:
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
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.
Algorithm Analysis PS5 due 11:59pm Wednesday, April 18 Final Project Phase 2 (Program Outline) due 1:30pm Tuesday, April 24 Wellesley College CS230.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. CSE 3101Z Design and Analysis of Algorithms.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
3.3 Complexity of Algorithms
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
Sorting.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Algorithm Analysis (Big O)
تصميم وتحليل الخوارزميات عال311 Chapter 3 Growth of Functions
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Searching Topics Sequential Search Binary Search.
CES 592 Theory of Software Systems B. Ravikumar (Ravi) Office: 124 Darwin Hall.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Data Structures and Algorithm Analysis Algorithm Analysis and Sorting
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Lecture 3COMPSCI.220.S1.T Running Time: Estimation Rules Running time is proportional to the most significant term in T(n) Once a problem size.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Lecture 2 Algorithm Analysis
CMPT 438 Algorithms.
Design and Analysis of Algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
Running Time Performance analysis
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
CS 3343: Analysis of Algorithms
Presentation transcript:

Computational Complexity 1. Time Complexity 2. Space Complexity

Measuring the Performance of algorithm Two important measures 1. Time Complexity 2. Space Complexity

Running Time of Algorithm = How much time the algorithm uses in terms of input size = # of certain operations used in the algorithm where each operation take a constant time. Like: multiplications, additions, comparisons, assignments, shifts, …etc ≠ # of seconds or minutes used by algorithm, because this depends on machine and technology (O.S., Prog. language, …etc)

Input Size vs. Input Type The running time is expressed in terms of input size and we concentrate our analysis on large inputs. Input types (arrays, lists, strings, integers,..etc) is not an issue here.

Algorithm Running Time Should be machine & technology independent. Should concentrate on the asymptotic times (large input size). Should concentrate on the main largest term (order of growth) and ignore the smaller ones. Sometimes we may even ignore the 1 st constant (multiplicative) factor. The constant factors or the other smaller terms are important when comparing two algorithms of the same order of running time. Asymptotic Notations are used to describe asymptotic behavior of algorithm.

Examples of Running Times (RT) Worst-case RT of Linear Search = θ(n) Worst-case RT of Binary Search = θ(log n) – Average however is still = θ ( log n ) RT of Selection Sort = n(n-1)/2 = θ(n 2 ) RT of Insertion Sort = Ω(n) and O(n 2 ) – Average however is still = θ(n 2 ) RT of Bottom Up Merge Sort = θ(n log n) # of comparisons = RT

Complexity of Running Time Could be Logarithmic = θ(log n) Linear = θ(n) Quadratic = θ(n 2 ) Cubic = θ(n 3 ) Polynomial = θ(n k ) … all are efficient.

How to compute the RT Ugly: by going through the code & counting iterations and operations Beautiful: by doing smart abstract analysis based on the idea of the algorithm

Space Complexity Is defined to be the extra space used by the algorithm beside the space allocated to hold the input I.e., it is the work space used by the algorithm measured by the number of cells or words.

EXamples Linear Search uses θ(1) (extra) space And so is Binary Search,,Selection Sort, and Insertion Sort Merge Sort however uses θ(n) extra space

Optimal Algorithms These are algorithms whose worst-case performances meet the best-case performance of any algorithm that solves the same problem Optimal RT = min { RT of A : A algorithm solves the problem}

EXample Merge Sort is optimal among all comparisons-based sorting algorithms, because it uses θ(n log n). Theorem: Any comparisons-based sorting algorithm uses Ω(n log n) cmps. There are however other non-cmp-based sorting algorithm that do better.

Worst-case vs. Average-case Which one is better – low worst-case with high average or – low average with high worst-case? The average is the average!

Input Size = n Sorting & searching: n = # of elements in the array Graphs: n, m = # of vertices & edges Integer Multiplications: n = # of bits Cryptography: n = # of bits