Complexity, Origami, etc. Big Oh Traditional Origami Fold and cut.

Slides:



Advertisements
Similar presentations
Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
Advertisements

Discrete Structures CISC 2315
Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
Lecture: Algorithmic complexity
 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
CS420 lecture one Problems, algorithms, decidability, tractability.
Analysys & Complexity of Algorithms Big Oh Notation.
Chapter 1 – Basic Concepts
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
Asymptotic Growth Rate
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
Introduction to Analysis of Algorithms
CS 307 Fundamentals of Computer Science 1 Asymptotic Analysis of Algorithms (how to evaluate your programming power tools) based on presentation material.
Eleg667/2001-f/Topic-1a 1 A Brief Review of Algorithm Design and Analysis.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
CS 461 – Nov. 21 Sections 7.1 – 7.2 Measuring complexity Dividing decidable languages into complexity classes. Algorithm complexity depends on what kind.
Asymptotic Notations Iterative Algorithms and their analysis
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.
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Lecture 2 Computational Complexity
Mathematics Review and Asymptotic Notation
Iterative Algorithm Analysis & Asymptotic Notations
Analysis of Algorithms
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
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.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
Asymptotic Analysis-Ch. 3
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Introduction to Programming (in C++) Complexity Analysis of Algorithms
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 2 Prepared by İnanç TAHRALI.
Algorithm Analysis Part of slides are borrowed from UST.
Chapter 2 Computational Complexity. Computational Complexity Compares growth of two functions Independent of constant multipliers and lower-order effects.
Asymptotic Analysis CSE 331. Definition of Efficiency An algorithm is efficient if, when implemented, it runs quickly on real instances Implemented where?
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.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis 1.
Chapter 2 Algorithm Analysis
Analysis of Algorithms
Analysis of Algorithms
Week 2 - Friday CS221.
CS 2210 Discrete Structures Algorithms and Complexity
Algorithm design and Analysis
Introduction to Algorithms Analysis
CS 201 Fundamental Structures of Computer Science
Analysis of Algorithms
Programming and Data Structure
8. Comparison of Algorithms
At the end of this session, learner will be able to:
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Complexity, Origami, etc. Big Oh Traditional Origami Fold and cut

Analyses of Algorithms What resources does an algorithm take? –runtime –space Calculate as function of size of input –size of set –magnitude of input values Typical problems –sort, search, paths/circuits of graph, Fibonacci, GCD –origami, 'off-line Tetris', piano-movers problem

Time complexity Can write program, run program and record time… Want machine independent analysis in terms of inputs –magnitude of inputs, size of set Count basic operations –For sorting, typically count compares Some judgment required Want bounds, not necessarily details

Example How many steps required to find average of N numbers in an array? Pseudo-code (array is aa, size n sum = aa[0]; set sum to the first number for (i=1;i<n;i++) { go through the array… sum = sum + aa[i]; } adding in the numbers How many steps? initialize sum 1 initialize i1 {compare i to n loop done completely n-1 times add aa[i] to sum 1 compare operation increment i } 3*(n-1) + 3

Big Oh Formal definition of upper bounds A function g(n) is said to be O(f(n)) if and only if the following is true: There exists a number n0 and a number c such that is n>n0 g(n) <= c*f(n) English: beyond a certain value of n, f(n) is an upper bound for g(n). You can use a coefficient c.

Jargon You say –g(n) is O(f(n)) –g(n) = O(f(n)) –g(n) є O(f(n)) (contained in, belongs to, is in) Generally, the f(n) functions are standard –O(log n), log NOTE: base doesn't matter –O(n), linear –O(n 2 ), n-squared, quadratic –O(n k ) for some k, polynomial, also called P –O(2 n ), exponential These may be 'NP' or NP-Complete

Exercise What is the relationship between log 2 (n) and ln(n) by definition: log e (n)

log n Why does base not matter? Because log b (n) = log b (a)*log a (n) this is the coefficient

NP, NP-complete Formal definition: an algorithm is NP if it can be performed by a non-deterministic Turing machine. Less formal: an algorithm is NP if it can be done by a process in which there are a finite number of choices, and assuming the correct choice is made, the process is polynomial. The correctness can be checked in polynomial time. If all choices must be tried, the algorithm is O(2 n ) NP-complete refers to a set of problems for which there are NP algorithms that have been shown to be equally hard –(can convert one to the other on polynomial time). –These include: traveling salesman, satisfying logical formulas, subgraph isomorphism. –BIG question in computer science proving either P = NP or P proper subset of NP.

Examples g(n) = 5n+10 is O(n) Let n0=10, c = 6, then if n>10 5*n+10 <= 5*n+n = 6*n g(n) = 3n 2 +5n+100 is O(n 2 ) Let n0 = 100, c=6, then if n>100 3n 2 +5n+100 <= 5n 2 +5n+100<=5n 2 +6n<= 5n 2 +n*n<= 6n 2

log n log n is O(n)—that is, log n is bounded by O(n) Assume base 2. Let n0=2, c=1 log n <= n Why? Raise 2 to each n <=2 n 2<2 2, 3<2 3, etc.

Big Oh This is an asymptotic, upper bound eventually, this is the n>n0 condition May not be a tight bound.

Bounds If g(n) is O(n), it is also O(n 2 ), O(n k ), O(2 n ) But, n 2 is not O(n)? Why? Suppose there was an n0 and a c, n 2 c and n>n0

Exercises g(n) = 4n 3 +n+10. Show g(n) is O(n 3 ) g(n) = log(n) * n. This is called log linear. Show it is O(n).

Growth rates illustrated n=1n=2n=4n=8n=16n=32 O(1) O(logn) O(n) O(nlogn) O(n2)O(n2) O(n 3 ), O(2 n )

Methods For loops, multiply number of steps in loop by upper bound on number of times loop is run For conditionals, add step for doing condition plus maximum of each of the branches

Lower bounds (omega) To give better performance estimates, we may also want to give lower bounds on growth rates Definition (omega): g(n) = Ω(f(n)) if there exist some constants c and n 0 such that g(n) ≥ cf(n) for all n ≥ n 0 This says, g(n) grows at least this much

“Exact” bounds Definition (Theta): g(n) = Θ(f(n)) if and only if g(n) =O(f(n)) and g(n) = Ω(f(n)). An algorithm is Θ(f(n)) means that f(n) is a tight bound (as good as possible) on its running time. –On all inputs of size n, time is ≤ f(n) –On all inputs of size n, time is ≥ f(n)

Complexity Bounds (such as Big Oh) are for specific algorithms –Tight[er] bounds are better than looser bounds –Sometimes there are reports giving average bounds Problems may have different algorithms with different bounds Sometimes possible to prove result about a problem as opposed to an algorithm –There is no method that is better than …

Good source Algorithm (Run Time) Analysis cs /cs201-algo-analysis.ppt

Computing Fibonacci numbers Recursive program 1 long int fib(n) function returns integer 2if (n <= 1) which case? 3 return 1; 0,1 case return 1 4else return fib(n-1) + fib(n-2) else calculate This is based on definition. It takes a long time [for big numbers]

fib(n) runs in exponential time Let T denote the running time. T(0) = T(1) = c T(n) = T(n-1) + T(n-2) + 2 where 2 accounts for line 2 plus the addition at line 3. It can be shown that the running time is Ω((3/2) n ). –at most and at least exponential

Efficient Fibonacci numbers Avoid recomputation –Work iteratively: working up and saving past results Solution with linear running time int fib(int n) { int fibn=0, fibn1=0, fibn2=1; set up 3 numbers if (n < 2) check case return n low(er) cases return n else { for( int i = 2; i <= n; i++ ) { loop fibn = fibn1 + fibn2; calculate fibn fibn1 = fibn2; reset fibn1 fibn2 = fibn; reset fibn2 } ends the looping return fibn; } ends the else clause } ends the function

Origami: paper folding Associated most with Japan Many oldest models come from China Independent development in Spain, elsewhere Worldwide Conventions all over: NYC in June

Water bomb Traditional model Can ask questions: –what is surface area? –what areas are on outside? –from folding pattern, what is foldable assignment of mountain and valley? What is folding order?

Modular origami 6 preliminary folds unit systems of models Rona Gurkewitz, others

Complexity and origami Many complexity questions have been addressed for origami, including: can a model be folded? Can a folding pattern be folded? Can a folding pattern with mountain and valley assignments be folded flat? 03/introdcgeom/demaine/2/index.html

Fold and cut Examples by Betsy Ross, Houdini, Martin Gardner (Scientific American), others. 5 pointed star

General problem Take a square Draw a polygon Is there a way to fold a flat model and make one cut to produce the polygon? Answer: Yes. –two ways. One way: generate skeleton, add perpendicular folds, then determine how to fold this pattern. –NP-complete

Conclusion Very big topic Active research Questions and comments?