AP National Conference, 2004 1 AP CS A and AB: New/Experienced A Tall Order? Mark Stehlik

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

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
CSE 373 Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
the fourth iteration of this loop is shown here
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
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.
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Cmpt-225 Algorithm Efficiency.
 Last lesson  Arrays for implementing collection classes  Performance analysis (review)  Today  Performance analysis  Logarithm.
Computer Science 2 Data Structures and Algorithms V section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1.
Data Structures CS 310. Abstract Data Types (ADTs) An ADT is a formal description of a set of data values and a set of operations that manipulate the.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Computer Science 2 Data Structures and Algorithms V Intro to “big o” Lists Professor: Evan Korth New York University 1.
David Luebke 1 8/17/2015 CS 332: Algorithms Asymptotic Performance.
Abstract Data Types (ADTs) Data Structures The Java Collections API
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Aaron Bauer Winter 2014.
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
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.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
CPS 100, Spring Analysis: Algorithms and Data Structures l We need a vocabulary to discuss performance and to reason about alternative algorithms.
Mathematics Review and Asymptotic Notation
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
CS 3343: Analysis of Algorithms
Analysis of Algorithms
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Catie Baker Spring 2015.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
CMSC 341 Asymptotic Analysis. 2 Complexity How many resources will it take to solve a problem of a given size? –time –space Expressed as a function of.
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
CompSci Analyzing Algorithms  Consider three solutions to SortByFreqs, also code used in Anagram assignment  Sort, then scan looking for changes.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Algorithm Analysis (Big O)
CompSci 100E 15.1 What is a Binary Search?  Magic!  Has been used a the basis for “magical” tricks  Find telephone number ( without computer ) in seconds.
Compsci 100, Fall Analysis: Algorithms and Data Structures l We need a vocabulary to discuss performance  Reason about alternative algorithms.
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.
Algorithm Complexity L. Grewe 1. Algorithm Efficiency There are often many approaches (algorithms) to solve a problem. How do we choose between them?
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
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.
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.
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Linda Shapiro Winter 2015.
CPS 100e 5.1 Inheritance and Interfaces l Inheritance models an "is-a" relationship  A dog is a mammal, an ArrayList is a List, a square is a shape, …
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
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.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
Analysis: Algorithms and Data Structures
Introduction to Algorithms
Compsci 201, Mathematical & Emprical Analysis
Tools: Solve Computational Problems
Algorithm Analysis (not included in any exams!)
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis
Algorithm design and Analysis
Introduction to Data Structures
PAC Intro to “big o” Lists Professor: Evan Korth New York University
Searching, Sorting, and Asymptotic Complexity
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Java Basics – Arrays Should be a very familiar idea
Presentation transcript:

AP National Conference, AP CS A and AB: New/Experienced A Tall Order? Mark Stehlik

AP National Conference, Schedule l 8:30 – 10:00  Intro, resources, what’s new l 10: :00  Design  Inheritance, Interfaces & Abstract Classes l 12:45 – 3:30  Collections -> Analysis -> Big O  Reading sample questions and their rubrics

AP National Conference, Intro l A v. AB? l Years teaching? l Java experience? l The cards (years teaching A/AB, 2 things) l Materials (AB q/ref, A2 & AB1 samples, role play)

AP National Conference, Resources l AP Central  Course descriptions  Java subset  Sample syllabi l AP list-serve l JETT workshops  8/6 & 7 at Florida International

AP National Conference, What’s new? l 2-D arrays to AB l Well, Java…  No reference parameters  Collections l But also…  Design  Analysis  Priority Queues

AP National Conference, Design l Interfaces – proscribe a set of behaviors  methods are public by default  NO implementation can be provided  NO instance variables can be declared  cannot, therefore, be instantiated what does that mean?  examples: stack and queue l Classes realize interfaces by implementing all methods

AP National Conference, Design… l vs. Abstract classes  some methods implemented  others designated as abstract (which forces the class to be abstract) – these must be implemented by class(es) that extend this abstract class (ultimately)  can have instance variables

AP National Conference, Design… l Let’s look at A2 l Let’s look at some other classes

AP National Conference, Collections l Lists, Sets, Maps l Raises the level of design (and discourse) l But, then, what is (are) the issue(s)?

AP National Conference, Collections… l What do they do?  List ordered (positionally) – a sequence duplicates?  Set unordered collection duplicates?  Map Maps (unique) keys to values

AP National Conference, Collections… l How do they do it?  Analyze their algorithms  But what does that mean?

AP National Conference, Algorithm Analysis (kudos to ola) l How do you measure performance?  It’s faster! It’s more elegant! It’s safer! It’s cooler! l Use mathematics to analyze the algorithm (performance as function of input size) l Implementation is another matter  cache, compiler optimizations, OS, memory,…

AP National Conference, What do we need? l Need empirical tests and mathematical tools  Compare by running 30 seconds vs. 3 seconds, 5 hours vs. 2 minutes Two weeks to implement code l We need a vocabulary to discuss tradeoffs

AP National Conference, What is big-Oh about? l Intuition: avoid details when they don’t matter, and they don’t matter when input size (N) is big enough  For polynomials, use only leading term, ignore coefficients: linear, quadratic y = 3x y = 6x-2 y = 15x + 44 y = x 2 y = x 2 -6x+9 y = 3x 2 +4x

AP National Conference, O-notation, family of functions first family is O(n), the second is O(n 2 )  Intuition: family of curves, same shape  More formally: O(f(n)) is an upper- bound, when n is large enough the expression cf(n) is larger  Intuition: linear function: double input, double time, quadratic function: double input, quadruple the time

AP National Conference, Reasoning about algorithms l We have an O(n) algorithm,  For 5,000 elements takes 3.2 seconds  For 10,000 elements takes 6.4 seconds  For 15,000 elements takes ….? l We have an O(n 2 ) algorithm  For 5,000 elements takes 2.4 seconds  For 10,000 elements takes 9.6 seconds  For 15,000 elements takes …?

AP National Conference, More formal definition O-notation is an upper-bound, this means that N is O(N), but it is also O(N 2 ) ; we try to provide tight bounds. Formally:  A function g(N) is O(f(N)) if there exist constants c and n such that g(N) n cf(N) g(N) x = n

AP National Conference, Other definitions l g(n) is O(f(n)) if lim g(n)/f(n) = c as n -> inf l Informally, think of O as “<=“ l Similarly, there’s a notation for lower bounds…

AP National Conference, Big-Oh calculations from code l Search for element in array:  What is complexity (using O-notation)?  If array doubles, what happens to time? for(int i=0; i < a.length; i++) { if (a[i].equals(target)) return true; } return false; l Best case? Average case? Worst case?

AP National Conference, Measures of complexity l Worst case  Good upper-bound on behavior  Never get worse than this l Average case  What does average mean?  Averaged over all inputs? Assuming uniformly distributed random data?

AP National Conference, Some helpful mathematics l … + N  N(N+1)/2 = N 2 /2 + N/2 is O(N 2 ) l N + N + N + …. + N (total of N times)  N*N = N 2 which is O(N 2 ) l … + 2 N  2 N+1 – 1 = 2 x 2 N – 1 which is O(2 N )

AP National Conference, The usual suspects l O(1) l O(log n) l O(n) l O(n log n) O( n 2 ) O( n 3 ) l … O( 2 n )

AP National Conference, Multiplying and adding big-Oh l Suppose we do a linear search then we do another one  What is the complexity?  If we do 100 linear searches?  If we do n searches on an array of size n?

AP National Conference, Multiplying and adding l Binary search followed by linear search?  What are big-Oh complexities? Sum?  50 binary searches? N searches? l What is the number of elements in the list (1,2,2,3,3,3)?  What about (1,2,2, …, n,n,…,n)?  How can we reason about this?

AP National Conference, Analysis for AP collections l ListQueue l ArrayStack (where’s the top?) l Lists, Maps, Sets

AP National Conference, Priority Queues l Idea l Implementation(s)

AP National Conference, Language details l No reference parameters  All passes are by value (primitives/objects) l How do you change something  Through “modifier” methods  Through returning a reference to a modified object (x = “changed x”)