CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.

Slides:



Advertisements
Similar presentations
HST 952 Computing for Biomedical Scientists Lecture 10.
Advertisements

90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 2: Basics Data Structures.
What is an Algorithm? (And how do we analyze one?)
CS 263.  Classification of algorithm against a model pattern ◦ Each model demonstrate the performance scalability of an algorithm  Sorting algorithms.
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.
Lecture 3 Aug 31, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis discussion of lab – permutation generation.
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
Bigointro1 Algorithm Analysis & Program Testing An introduction.
© Janice Regan, CMPT 128, Feb CMPT 128: Introduction to Computing Science for Engineering Students Running Time Big O Notation.
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)
Object-Oriented Design CSC 212. Announcements Ask more questions!  Your fellow students have the same questions (remember, I grade the daily quizzes)
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
M180: Data Structures & Algorithms in Java Algorithm Analysis Arab Open University 1.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
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.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Searching Topics Sequential Search Binary Search.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 4.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
LECTURE 22: BIG-OH COMPLEXITY CSC 212 – Data Structures.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
Big-O notation.
Introduction to Analysis of Algorithms
CprE 185: Intro to Problem Solving (using C)
Design and Analysis of Algorithms Chapter -2
ADT Implementation: Recursion, Algorithm Analysis, and Standard Algorithms Chapter 10 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second.
CSC 427: Data Structures and Algorithm Analysis
Algorithmic complexity: Speed of algorithms
Analysis of Algorithms
Algorithmic Efficency
COMP108 Algorithmic Foundations Algorithm efficiency
Introduction to complexity
Introduction to Algorithms
Big-O notation.
Introduction to Algorithms
CSC 108H: Introduction to Computer Programming
Course Description Algorithms are: Recipes for solving problems.
Efficiency (Chapter 2).
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
ITEC 2620M Introduction to Data Structures
Introduction to Data Structures
Searching and Sorting Topics Sequential Search on an Unordered File
Big O Notation.
CS 201 Fundamental Structures of Computer Science
Algorithm Discovery and Design
Searching and Sorting Topics Sequential Search on an Unordered File
Algorithmic complexity: Speed of algorithms
Searching, Sorting, and Asymptotic Complexity
Analysis of Algorithms
CSC 427: Data Structures and Algorithm Analysis
Algorithmic complexity: Speed of algorithms
Data Structures Introduction
slides created by Ethan Apter
Analysis of Algorithms
Richard Anderson Winter 2019 Lecture 4
Course Description Algorithms are: Recipes for solving problems.
Analysis of Algorithms
Design and Analysis of Algorithms
Richard Anderson Autumn 2015 Lecture 4
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
Presentation transcript:

CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki

August Administration ● Assignment updates. ● Brief exam information.

August Judging Programs. ● We can judge programs by correctness, and whether they meet specifications. ● We use testing and proofs to do this. ● We can judge them by legibility. ● We have style guides to help us with this. ● Finally we can judge them by how fast they run. ● ?

August Judging speed. ● Obviously, we want our programs to run as fast as possible. ● One way is just to time our programs. ● But there are a few things that make this not as useful as it seems. ● Differing architectures. ● Moore's Law. ● Differing input sizes.

August Architectures. ● Code can often run much faster on one machine than another. ● It can even run faster if it's written in certain programming languages vs. others on the same machine. ● So if we time our programs, how do we know we're testing the quality of the algorithm, and not just how well our program matches the architecture?

August Moore's Law ● Says that processing power doubles every 18 months. ● Although that number is up for debate. ● Still the point is that computer speed increases fast. ● So if we compare times on different machines we may just be testing the machines and not the algorithms.

August Input Sizes. ● Moore's law means that the maximum 'reasonable' input size for our algorithm is constantly increasing. ● But what if our program does well at small inputs, but once it hits some threshold it becomes much slower than other algorithms. ● For example, insertion sort is optimal for small (<7 or so) inputs. ● How can we be certain that our algorithm scales well?

August Recap. ● We want a way of judging programs that is: ● Architecture independent. ● Captures how the program scales. ● Is independent of the speed of the computer we're running our tests on.

August Computational Complexity ● What computational complexity is, very roughly, is reading code and making a rough estimate of how long it takes per input size. ● Each line of code that is executed is counted as one step. ● So an arithmetic statement is considered to count as much as a boolean expression which is as much as a print statement. ● This is an oversimplification, but it is reasonable due to Moore's law.

August Counting Steps: ● What about code that does a varying number of steps? ● Like and if/elif block. Maybe one block of code has a single statement, and the other has 20 statements. ● In this case we will use Worst-Case analysis, and always assume that the longest block of code is executed.

August Counting Steps: ● What about loops? ● Here we count the number of lines in the loop block, times the number of times the loop is executed. ● Keep in mind that if we have nested loops, then to get the total number of lines of code we execute, we need to multiply the number of times the inner loop runs time the number of times the outer loop runs. ● For while loops we need to consider the worst-case scenario.

August Counting Steps: ● So if we've counted all the steps we get a rough mathematical formula that tells us how many steps the code takes to run. ● Because of Moore's law, we tend to ignore constants, and just focus on the biggest term that involves the input size. ● If we assume that the input size is n, then we care only about the biggest term with n in it (after we've removed the constants).

August Some general guidelines: ● Always take the worst case if your code depends on boolean expressions. ● Constants aren't important. ● We'll see why this is formally in 165. ● But roughly, this has to do with the way functions grow at large numbers. – Which we justify using Moore's law. ● A for loop that depends on list or dictionary length almost always adds a power of n. ● So a lot of basic complexity analysis is just counting for loops.

August Breaks,

August Base 10 notation. ● Regular number notation is base 10. ● That is, we have 10 digits (0-9), and each digit in a number tells us how many of a power of 10 we have. ● So we can write: ● 59 = 5 * 10**1 + 9 * 10**0 ● = 2 * 10**5 + 3 * 10**4 + 7 * 10**3 + 8 * 10**2 + 9 * 10**1 + 6 * 10**0

August What if we didn't have 10 digits? ● What if we only had 5 digits (0-4). ● Well we could still write 21 as 2 * 10**1 + 1 * 10**0. ● But if we want to write 27 in base 4? We can't do anything in the form 2 * 10**1 + x * 20 ** 0, because that will only get us number from 20 to 24. And if we change the first digit to 3 then the lowest we can go is 20

August What if we didn't have 10 digits? ● So clearly we can't use 10 as our powers. ● But we say that when we had 10 digits, we used 10 as our base. ● So if we only have 5, then we should use 5 as our base. ● So now when we write 21 5 in a base 5 system that means 2 * 5 ** * 5 or 11 in our regular base 10 system.

August Binary notation. ● Binary is just a base-2 system. ● So a number system when we only have two characters (0-1). ● Used in computers due to hardware reasons (since there are only two options, can represent them as high and low voltages). ● So is 1 * 2**6 + 0 * 2**5 + 1 * 2**4 + 0 * 2**3 + 1 * 2**2 + 1 * 2**1 + 0 * 2**0.

August Some useful tricks. ● If we want to get only the lowest k bits of a base j system from a number n, we do: ● n % j**k ● If we want to get only bits that are higher than the lowest k bits in a base j system from a number n, we do: ● n / j**k ● We can use these to clear out low or high order bits, or to figure out what a specific bit is.