CEG 221 Lesson 5: Algorithm Development II Mr. David Lippa.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Numerical Solution of Linear Equations
MATH 224 – Discrete Mathematics
Gaussian Elimination Matrices Solutions By Dr. Julia Arnold.
Chapter 9: Searching, Sorting, and Algorithm Analysis
Theoretical Program Checking Greg Bronevetsky. Background The field of Program Checking is about 13 years old. Pioneered by Manuel Blum, Hal Wasserman,
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
INFINITE SEQUENCES AND SERIES
Introduction to Analysis of Algorithms
CEG 221 Lesson 1: Review I Mr. David Lippa. Overview: Review of Required Concepts Basic data types –Normal basic types, size_t, time_t Basic programming.
MECH300H Introduction to Finite Element Methods Lecture 2 Review.
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
The Efficiency of Algorithms
Lecture 3 Aug 31, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis discussion of lab – permutation generation.
Ch 7.2: Review of Matrices For theoretical and computation reasons, we review results of matrix theory in this section and the next. A matrix A is an m.
CEG 221 Lesson 4: Algorithm Development I Mr. David Lippa.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Matrices MSU CSE 260.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
1 i206: Lecture 6: Math Review, Begin Analysis of Algorithms Marti Hearst Spring 2012.
1 1.1 © 2012 Pearson Education, Inc. Linear Equations in Linear Algebra SYSTEMS OF LINEAR EQUATIONS.
Pointers (Continuation) 1. Data Pointer A pointer is a programming language data type whose value refers directly to ("points to") another value stored.
Exercise problems for students taking the Programming Parallel Computers course. Janusz Kowalik Piotr Arlukowicz Tadeusz Puzniakowski Informatics Institute.
Chapter 10 Review: Matrix Algebra
Chapter 1 Algorithm Analysis
Analysis CS 367 – Introduction to Data Structures.
Review of Matrices Or A Fast Introduction.
Statistics and Linear Algebra (the real thing). Vector A vector is a rectangular arrangement of number in several rows and one column. A vector is denoted.
Analysis of Algorithms
Matrices Addition & Subtraction Scalar Multiplication & Multiplication Determinants Inverses Solving Systems – 2x2 & 3x3 Cramer’s Rule.
Riemann Sums, Trapezoidal Rule, and Simpson’s Rule Haley Scruggs 1 st Period 3/7/11.
1 CSC 427: Data Structures and Algorithm Analysis Fall 2008 Algorithm analysis, searching and sorting  best vs. average vs. worst case analysis  big-Oh.
Maybe add in chad’s idea of the area of polygons limiting to the area of a circle. Nice animation to link to online At
In section 11.9, we were able to find power series representations for a certain restricted class of functions. Here, we investigate more general problems.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
Algorithm Analysis Data Structures and Algorithms (60-254)
Problem of the Day  I am thinking of a question and propose 3 possible answers. Exactly one of the following is the solution. Which is it? A. Answer 1.
Analysis of Algorithms Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
4.5 Inverse of a Square Matrix
Area Under the Curve We want to approximate the area between a curve (y=x 2 +1) and the x-axis from x=0 to x=7 We want to approximate the area between.
 In this lesson we will go over how to solve a basic matrix equation such as the following: These are matrices, not variables.
Searching Topics Sequential Search Binary Search.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
Notes Over 4.2 Finding the Product of Two Matrices Find the product. If it is not defined, state the reason. To multiply matrices, the number of columns.
5.3 Definite Integrals. Example: Find the area under the curve from x = 1 to x = 2. The best we can do as of now is approximate with rectangles.
Matrix Arithmetic Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB.
Matrices. Matrix - a rectangular array of variables or constants in horizontal rows and vertical columns enclosed in brackets. Element - each value in.
LECTURE 22: BIG-OH COMPLEXITY CSC 212 – Data Structures.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
10.4 Warm up – No Calc. Section 10.4 – Determinant of a SQUARE Matrix With and Without Calculator By the end of this lesson, you should be able to: Calculate.
Week 1 Real Numbers and Their Properties (Section 1.6, 1.7, 1.8)
Numerical Algorithms Chapter 11.
13.4 Product of Two Matrices
Introduction to Analysis of Algorithms
12-1 Organizing Data Using Matrices
ECE 3301 General Electrical Engineering
DETERMINANTS A determinant is a number associated to a square matrix. Determinants are possible only for square matrices.
Objectives Multiply two matrices.
Matrices.
Memory System Performance Chapter 3
Determinants 2 x 2 and 3 x 3 Matrices.
Determinants 2 x 2 and 3 x 3 Matrices.
Presentation transcript:

CEG 221 Lesson 5: Algorithm Development II Mr. David Lippa

Overview Algorithm Development II –Review of basic algorithm development –Advanced algorithm development Optimization of algorithm Optimization of code Questions

What is an Algorithm? An algorithm is a high-level set of clear, step-by-step actions taken in order to solve a problem, frequently expressed in English or pseudo code. Examples of Algorithms: –Computing the remaining angles and side in an SAS Triangle –Computing an integral using rectangle approximation method (RAM) or the Trapezoidal Rule

Example: Triangulation with SAS If we return to the SAS triangle, there’s nothing really much to be done to improve speed or efficiency, as the computation is very straightforward. B a = 60 42° b = 100 A C

Example: Trapezoidal Rule You notice that we compute f(x) more times than is necessary for all the inner values Let’s compute SUM2 = 2 * ( f(0) + f(0.25) + f(0.5) + f(0.75) + f(1.0) ) – f(0) – f(1.0). AREA2 = 0.5 * SUM2 4 trapezoids  8 computations of f 8 trapezoids  12 computations of f 1024 trapezoids  1028 computations If the interval here is [0, 1], then we need to compute: SUM = ( f(0) + f(0.25) + f(0.25) + f(0.5) + f(0.5) + f(0.75) + f(0.75) + f(1.0) ). Then, AREA = 0.5 * SUM. 4 trapezoids  9 computations of f 8 trapezoids  15 computations of f 1024 trapezoids  2047 computations Notice a pattern?

Trapezoidal Rule Improvements For a small number of trapezoids, this method is slightly more work. For, say 1024 trapezoids, this is significantly more efficient in terms of number of mathematical calculations. CONCLUSION: Given that greater accuracy comes with more trapezoids, this optimization is sufficient, since this algorithm will rarely be used with few trapezoids.

Optimizing Implemented Code There are other ways to speed up code –Sacrifice memory for improved speed (ie. Always try to work from memory, not from disk) –Avoid algorithms where the ratio of work required to number of elements processed is n, namely an n 2 algorithm. –Pass by reference or pointer where appropriate to prevent unnecessary memory copies of large structures –Use algorithm analysis to try to find the cause of the lack of speed

Algorithm Analysis Big-Oh notation – how much work is required to process n inputs in terms of n –Constants are less important for Big-Oh notation –O(1), O(log 2 n), O(n), O(n log 2 n), O(n 2 ), O(n 3 ), O(2 n ), O(n!) –Associate algorithms with each Matrix, Integration, SAS, factorial Formal definition

Using Algorithm Analysis Analyze an algorithm by computing the number of operations performed per unit input Avoid O(n 2 ) or worse algorithms Convert code to pseudo code if needed, to do a theoretical analysis

Algorithm Analysis: Example Matrix Multiplication –Pseudo code – To multiply an m x n matrix [A] and an n x p matrix [B], dot product each row of [A] with each column of [B]. Results in m * p dot products (see previous notes for pseudo code details) Dot product –Pseudo code – to dot product two vectors, multiply the first element of each, the second, the third, and so on and add them all together Results in n multiplication and addition operations (see previous notes for pseudo code details) RESULT: Matrix multiplication is an O(m * n * p) operation. With square matrices, it is O(n 3 )

Next Time Building Libraries Using Libraries Tradeoffs Questions

Questions?