John Levine, Computer and Information Sciences, Strathclyde University 1 Algorithms and Complexity 2: Complexity Notation.

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

12-Apr-15 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
Lecture 12: Revision Lecture Dr John Levine Algorithms and Complexity March 27th 2006.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 2: Basics Data Structures.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Analysys & Complexity of Algorithms Big Oh Notation.
Computational Complexity 1. Time Complexity 2. Space Complexity.
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Introduction to Analysis of Algorithms
Wednesday, 11/25/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/25/02  QUESTIONS??  Today:  More on sorting. Advanced sorting algorithms.  Complexity:
Analysis of Algorithms. Time and space To analyze an algorithm means: –developing a formula for predicting how fast an algorithm is, based on the size.
Runtime Analysis CSC 172 SPRING 2002 LECTURE 9 RUNNING TIME A program or algorithm has running time T(n), where n is the measure of the size of the input.
Cmpt-225 Algorithm Efficiency.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 1. 2 Big Oh and other notations Introduction Classifying functions by their asymptotic growth Theta, Little oh,
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 2. Types of Complexities.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
COMPSCI 102 Introduction to Discrete Mathematics.
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
1 Complexity Lecture Ref. Handout p
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
1.2. Comparing Algorithms. Learning outcomes Understand that algorithms can be compared by expressing their complexity as a function relative to the size.
Object-Oriented Design CSC 212. Announcements Ask more questions!  Your fellow students have the same questions (remember, I grade the daily quizzes)
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Ch 18 – Big-O Notation: Sorting & Searching Efficiencies Our interest in the efficiency of an algorithm is based on solving problems of large size. If.
Lecture 6: Problem Solving Dr John Levine Algorithms and Complexity February 10th 2006.
CSCI 3160 Design and Analysis of Algorithms Tutorial 1
Department of Computer Science 1 COSC 2320 Section Room 104 AH 5:30 – 7:00 PM TTh Professor Olin Johnson Office 596 PGH
Lecture 7: Uninformed Search Dr John Levine Algorithms and Complexity February 13th 2006.
Introduction to: Programming CS105 Lecture: Yang Mu.
Lecture 3 Analysis of Algorithms, Part II. Plan for today Finish Big Oh, more motivation and examples, do some limit calculations. Little Oh, Theta notation.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
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.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
3.3 Complexity of Algorithms
Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
Week 12 - Friday.  What did we talk about last time?  Finished hunters and prey  Class variables  Constants  Class constants  Started Big Oh notation.
27-Jan-16 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
Searching Topics Sequential Search Binary Search.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
DS.A.1 Algorithm Analysis Chapter 2 Overview Definitions of Big-Oh and Other Notations Common Functions and Growth Rates Simple Model of Computation Worst.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
AP National Conference, AP CS A and AB: New/Experienced A Tall Order? Mark Stehlik
Section 1: Problem solving AQA Computing A2 © Nelson Thornes 2009 Examples of problems with different time complexities Section 1.2: Comparing algorithms.
CMPT 120 Topic: Searching – Part 2
Introduction to complexity
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Introduction to Algorithms
Lesson Objectives Aims Understand the following: The big O notation.
Great Theoretical Ideas in Computer Science
Introduction to Data Structures
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Big O Notation.
Analysys & Complexity of Algorithms
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Searching, Sorting, and Asymptotic Complexity
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
CMPT 120 Lecture 33 – Unit 5 – Internet and Big Data
Presentation transcript:

John Levine, Computer and Information Sciences, Strathclyde University 1 Algorithms and Complexity 2: Complexity Notation John Levine

John Levine, Computer and Information Sciences, Strathclyde University 2 Last time What’s an algorithm then? –Intro and brief history –Sample use of algorithms –Sample algorithm - room count Course overview –Lectures, practical, labs/tuts, the exam

John Levine, Computer and Information Sciences, Strathclyde University 3 The travelling seller Mary, a computer seller, needs to visit 3 shops in a day (starting and finishing at the office): what’s the shortest route? What if there’s 12 shops? 5km 3km 2km 8km 12km

John Levine, Computer and Information Sciences, Strathclyde University 4 Today Size matters Complexity notation Calculating complexities 2

John Levine, Computer and Information Sciences, Strathclyde University 5 Download time from internet Say it takes 2s to establish a link and then we download at 5K/s, then if n is size of file in K: –time to download is n / –a linear function –dominant element as data size grows is n, so using big-oh notation = O(n)

John Levine, Computer and Information Sciences, Strathclyde University 6 String Search Problem: –Find a string t in a longer string s Simple approach i=0; found = false; while (!found) & (i<s.length) j = 0; oksofar = true; while (oksofar) & (j<t.length()) if (s.charAt(i+j)!=t.charAt(j)) oksofar = false; j++ found = oksofar; i++;

John Levine, Computer and Information Sciences, Strathclyde University 7 Rules for big-oh notation Only record the highest, dominant, factor Ignore constants and multipliers Kind of like rounding 1,000,001 is roughly 1,000,000 so you say O(n 2 ) and not O(12n 2 ) 4n 3 + 3n n = O(n 3 ) 3n = O(n 3 )

John Levine, Computer and Information Sciences, Strathclyde University 8 Common classes of Big-Oh In increasing complexity roughly: - logarithmic O(log n) - linear O(n) - lin-log O(n log n) - quadratic O(n 2 ) - polynomial O(n k ), k > 1 - exponential O(a n ), n > 1 - factorial O(n!), n > 1

John Levine, Computer and Information Sciences, Strathclyde University 9 Common classes of Big-Oh

John Levine, Computer and Information Sciences, Strathclyde University 10 Tyranny of complexity 1000 items per sec plus 10 secs startup

John Levine, Computer and Information Sciences, Strathclyde University 11 = Big-Oh says “as the numbers grow the dominant factor will be no worse (<=) than given” –e.g. an O(n log n) function grows no faster than another t = n log n Big-Oh is used for the worst case - we will mostly talk worst, sometimes expected but never best nor average Also Ω(n) and θ(n) for >= and =

John Levine, Computer and Information Sciences, Strathclyde University 12 Simple String Search Peter Piper picked a peck of pickled pepper; A peck of pickled pepper Peter Piper picked. If Peter Piper picked a peck of pickled pepper, Where’s the peck of pickled pepper Peter Piper picked? Find pepper - lots of false starts Can you do better? Simple complexity is O(nm)

John Levine, Computer and Information Sciences, Strathclyde University 13 Better string search Start search at end and keep a table peter_piper picked a peck of pickled pepper pepperpiper_picked a peck of pickled pepper peter pepperpicked a peck of pickled pepper peter piper pepper a peck of pickled pepper peter piper pickedpepperk of pickled pepper peter piper picked a pecpepperickled pepper peter piper picked a peck pepperkled pepper peter piper picked a peck of picpepperepper peter piper picked a peck of picklpepperper peter piper picked a peck of pickledpepperr pepper peter piper picked a peck of pickled pepper 10 steps instead of 50 (I think) what about longer text? what about fewer letters - e.g. DNA coding? AGCCCGAACATTTACGCCGCTGGCGACTGCACCG

John Levine, Computer and Information Sciences, Strathclyde University 14 String search Basic algorithm is O(nm) Best algorithm is O(n) –BUT is much more complex Have to think of when it matters –is data big enough for more complex soln –watch constants and multipliers

John Levine, Computer and Information Sciences, Strathclyde University 15 Summary Size matters Complexity notation Calculating complexities Next time: start searching & sorting Ask the class quiz