Complexity and Big-O.

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
22C:19 Discrete Math Algorithms and Complexity
MATH 224 – Discrete Mathematics
Analysys & Complexity of Algorithms Big Oh Notation.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Cmpt-225 Algorithm Efficiency.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
1 Discrete Mathematics Summer 2004 By Dan Barrish-Flood originally for Fundamental Algorithms For use by Harper Langston in D.M.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
Algorithm Analysis (Big O)
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
Big Oh Algorithm Analysis with
Design and Analysis Algorithm Drs. Achmad Ridok M.Kom Fitra A. Bachtiar, S.T., M. Eng Imam Cholissodin, S.Si., M.Kom Aryo Pinandito, MT Pertemuan 04.
1.2. Comparing Algorithms. Learning outcomes Understand that algorithms can be compared by expressing their complexity as a function relative to the size.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
Asymptotic Analysis-Ch. 3
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
Asymptotic Notation (O, Ω, )
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.
Introduction to: Programming CS105 Lecture: Yang Mu.
Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation.
Big-O. Algorithm Analysis Exact analysis: produce a function f(n) measuring how many basic steps are needed for a given inputs n On any input of size.
Analysis of Algorithm. Why Analysis? We need to know the “behavior” of algorithms – How much resource (time/space) does it use So that we know when to.
تصميم وتحليل الخوارزميات عال311 Chapter 3 Growth of Functions
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.
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
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Mathematical Foundations (Growth Functions) Neelima Gupta Department of Computer Science University of Delhi people.du.ac.in/~ngupta.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Design and Analysis of Algorithms
May 17th – Comparison Sorts
Algorithmic complexity: Speed of algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
Introduction to Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Lesson Objectives Aims Understand the following: The big O notation.
Complexity analysis.
Week 2 - Friday CS221.
Growth of functions CSC317.
Complexity and Big-O.
CS 2210 Discrete Structures Algorithms and Complexity
Efficiency (Chapter 2).
ITEC 2620M Introduction to Data Structures
GC 211:Data Structures Algorithm Analysis Tools
Introduction to Data Structures
CSCI 2670 Introduction to Theory of Computing
CSC 413/513: Intro to Algorithms
Big O Notation.
Comparing Algorithms Unit 1.2.
CS 2210 Discrete Structures Algorithms and Complexity
Analysys & Complexity of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Algorithmic complexity: Speed of algorithms
Recurrences (Method 4) Alexandra Stefan.
Searching, Sorting, and Asymptotic Complexity
CSE 373: Data Structures & Algorithms
Performance Evaluation
Algorithmic complexity: Speed of algorithms
slides created by Ethan Apter
Algorithm Analysis.
CMPT 225 Lecture 6 – Review of Complexity Analysis using the Big O notation + Comparing List ADT class implementations.
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Complexity and Big-O

Can computer compute everything??? Why and Why not? The general answer is NO, computer can’t compute everything! We will discuss reasons in this section.

Let’s try out the program we know Run tower_of_hanoi with 10, 15, 20, 23, 24, or 30 discs …

The Wheat and Chessboard Problem The inventor of chess (in some tellings Sessa, an ancient Indian Minister) request his ruler give him wheat according to the Wheat and Chessboard Problem. The ruler laughs it off as a meager prize for a brilliant invention, only to have court treasurers report the unexpectedly huge number of wheat grains would outstrip the ruler's resources. https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem

The problem Add them up 1+2+4+… = 1+2+4+…+264 = 8 16 32 … ??? Add them up 1+2+4+… = 1+2+4+…+264 = 18,446,744,073,709,551,615 !!!

What does it have anything to do with CS? If your program requires 2n steps to compute something, it is not practical to expect any results in a meaningful time frame for the problem of reasonable large input size n, e.g., a few tens or a few hundreds. In our Wheat and Chessboard problem, n = 64. Steps = 18,446,744,073,709,551,615. A modern desk-top computer (4GHz) can do roughly 4 billion steps per second. To go through that many steps, it would take 584,943,368 centuries!!!

Why does this matter? Computers are so fast! But… Large Scale Data Google, Twitter, Facebook.. Big Data

5 EXABYTES of new information in 2002 161 EXABYTES of new information in 2006 1200 EXABYTES of new information in 2010 [Lyman 03, Gantz 07, Gantz 10] 2019????

Why does this matter? Computers are so fast! But… Large Scale Data Google, Twitter, Facebook.. Big Data Limited Resources phones, watches, wearable computing High Performance Environments milliseconds matter

How do we know what matters in code? 1 1 * (n) 1 n+2

How do we know what matters in code? O(n) Pay attention to what changes as the variables increases

Selection sort O(n2) def sortByTitle(self): ''' Sort the album by the title, without change the original data Here we use insert sort as students saw it in hw3 for i in range(len(self)): # n minIndex = self.findMinIndex(self.sortedByTitles, i) # n-i self.swap(minIndex, i, self.sortedByTitles) # 1 O(n2)

Big-O Notation No need to count precise number of steps Classify algorithms by order of magnitude Execution time Space requirements Big O gives us a rough upper bound Goal is to give you intuition

Describing Growth Let’s try the program … bigO.py The first one is constant time O(1), the second one is logarithm time O(log n), the last one is exponential time O(2n), rest polynomial time O(nk). Let’s try the program … bigO.py

For polynomial time

For exponential time Pay attention to the problem size and the actual timing.