C++ For Science and Engineering Lecture 10

Size: px
Start display at page:

Download "C++ For Science and Engineering Lecture 10"

Transcription

1 C++ For Science and Engineering Lecture 10 John Chrispell Tulane University Wednesday 15, 2010

2 Introducing for loops Often we want programs to do the same action more than once. #i n c l u d e <iostream > i n t main ( ) { using namespace s t d ; i n t i ; // c r e a t e a c o u n t e r / i n i t i a l i z e ; t e s t ; update / f o r ( i = 0 ; i < 5 ; i ++){ cout << Counting Sheep << i <<. \ n ; cout << ZZZZZZZZZZzzzzzzz..... \ n ; return 0 ; You may use the increment operator anywhere, not just in loops. John Chrispell, Wednesday 15, 2010 slide 3/27

3 Introducing for loops For loops handel the following steps: 1 Setting a value initially. 2 Performing a test to see whether the loop shoudl continue. Typically a relational statement or one that compares two values. At its heart this is a true or false statement. Every expression has value as will be seen in an upcoming listing. 3 Executing the loop actions. 4 Updating value(s) used for the test. John Chrispell, Wednesday 15, 2010 slide 5/27

4 The design of for loops John Chrispell, Wednesday 15, 2010 slide 7/27

5 Value of expressions express.cpp Consider the value of some expressions: #i n c l u d e <iostream > i n t main ( ) { using namespace std ; i n t x ; cout << The e x p r e s s i o n x = 100 has the v a l u e ; cout << ( x = 100) << endl ; cout << Now x = << x << endl ; cout << The e x p r e s s i o n x < 3 has the v a l u e ; cout << ( x < 3) << endl ; cout << The e x p r e s s i o n x > 3 has the v a l u e ; cout << ( x > 3) << endl ; / ======================= / / a newer C++ f e a t u r e / / ======================= / cout. s e t f ( i o s b a s e : : b o o l a l p h a ) ; cout << The e x p r e s s i o n x < 3 has the v a l u e ; cout << ( x < 3) << endl ; cout << The e x p r e s s i o n x > 3 has the v a l u e ; cout << ( x > 3) << endl ; return 0 ; John Chrispell, Wednesday 15, 2010 slide 9/27

6 numtest.cpp The following listing has code that counts down! #i n c l u d e <iostream > i n t main ( ) { using namespace s t d ; cout << Enter the s t a r t i n g countdown v a l u e : ; i n t l i m i t ; c i n >> l i m i t ; i n t i ; f o r ( i = l i m i t ; i ; i ){ // q u i t s when i i s 0 cout << i = << i << \n ; cout << Done now t h a t i = << i << \n ; return 0 ; Note we don t enter the loop if limit is 0. John Chrispell, Wednesday 15, 2010 slide 11/27

7 for loops in C++ and C There is a difference in for loops in C and C++. In C++ you can declare and initialize a variable in a for loop. f o r ( i n t i = 2 0 ; i > 0 ; i ) cout << i = << i << \n ; / i o n l y e x i s t s i n the l o o p / cout << i << e n d l ; // Not v a l i d as i dosn t e x i s t. Note we can omit the braces around the for loop if we feel lazy. Now lets us a loop to calculate factorials! John Chrispell, Wednesday 15, 2010 slide 13/27

8 factorial.cpp #i n c l u d e <iostream > using namespace s t d ; const i n t A r S i z e = 1 6 ; / example o f e x t e r n a l d e c l a r a t i o n / i n t main ( ) { double f a c t o r i a l s [ A r S i z e ] ; f a c t o r i a l s [ 1 ] = f a c t o r i a l s [ 0 ] = 1. 0 ; f o r ( i n t i = 2 ; i < A r S i z e ; i ++){ f a c t o r i a l s [ i ] = i f a c t o r i a l s [ i 1]; cout << Values : << e n d l ; f o r ( i n t j = 0 ; j < A r S i z e ; j ++) cout << j <<! = << f a c t o r i a l s [ j ] << e n d l ; return 0 ; John Chrispell, Wednesday 15, 2010 slide 15/27

9 forstrings.cpp // f o r s t r 1. cpp u s i n g f o r with a s t r i n g #include <i o s t r e a m > #include <s t r i n g > i n t main ( ) { using namespace s t d ; cout << Enter a s t r i n g : ; s t r i n g word ; g e t l i n e ( cin, word ) ; / ================================ / / d i s p l a y l e t t e r s i n r e v e r s e o r d e r / / ================================ / f o r ( i n t i = word. s i z e ( ) 1 ; i >= 0 ; i ){ cout << word [ i ] ; cout << \ndone!. \ n ; return 0 ; John Chrispell, Wednesday 15, 2010 slide 17/27

10 ++ vs. The increment (++) and decrement ( ) operators can be use two ways. 1 Prefix : --i 2 Postfix : i++ One advances the index after the execution of the statement. The other indexes the variable then executes the statement. C++ compilers make no garuntees when you mix these operators within a statement. v a l u e = i ( i ) ; // This s h o u l d be a v o i d e d. In a loop there is no difference between: f o r ( n = l i m ; n > 0 ; n ) s tatement ; f o r ( n = l i m ; n >0; n ) s tatement ; There may be a small difference in speed of execution. John Chrispell, Wednesday 15, 2010 slide 19/27

11 ++, and pointers The increment (++) and decrement ( ) operators can be use with pointers. Consider the following double a r r [ 5 ] = { , , , , ; / Set the p o i n t e r pt to a r r [ 0 ], i. e. to 21.1 / double pt = a r r ; / Advance the p o i n t e r to a r r [ 1 ], i. e / pt++; You can also change the value pointed to by using the dereference operator. / I n c r e m e nt the p o i n t e d to v a l u e / ( pt )++; // or ++ pt / D e r e f e r e n c e o r i g. l o c a t i o n, then i n c r e m e n t p o i n t e r / pt++; John Chrispell, Wednesday 15, 2010 slide 21/27

12 more for your bag of tricks C++ and even C allow for combinations of operators: / Combined Assignment O p e r a t o r s / += A s s i g n s L + R to L = A s s i g n s L R to L = A s s i g n s L R to L /= A s s i g n s L/R to L %= A s s i g n s L%R to L You may use these at will. i += 5 ; j = v a l u e ; But now that we have loops we need to make sure we format the code so that we can read it. Please USE BLOCKS!!! Note variables declared in blocks live only in those blocks. The also mask variables of the same name! John Chrispell, Wednesday 15, 2010 slide 23/27

13 block.cpp #i n c l u d e <iostream > i n t main ( ) { using namespace std ; cout << The Amazing Accounto w i l l sum and average ; cout << f i v e numbers f o r you. \ n ; cout << P l e a s e e n t e r f i v e v a l u e s : \ n ; double number ; double sum = 0. 0 ; f o r ( i n t i = 1 ; i <= 5 ; i ++){ // b l o c k s t a r t s h e r e i n s i d e l o o p cout << Value << i << : ; c i n >> number ; sum += number ; cout << F i v e e x q u i s i t e c h o i c e s i n d e e d! ; cout << They sum to << sum << endl ; cout << and a v e r a g e to << sum / 5 <<. \ n ; cout << The Amazing Accounto b i d s you adieu! \ n ; return 0 ; John Chrispell, Wednesday 15, 2010 slide 25/27

14 forstr2.cpp An example of how a, can be used to put two expressions into a single statement. #i n c l u d e <iostream > #i n c l u d e <s t r i n g > i n t main ( ) { using namespace std ; cout << Enter a s t r i n g : ; s t r i n g word ; g e t l i n e ( cin, word ) ; char temp ; i n t i, j ; / Use, to s e p a r a t e two e x p r e s s i o n s / f o r ( j = 0, i = word. s i z e ( ) 1 ; j < i ; i, ++j ){ temp = word [ i ] ; word [ i ] = word [ j ] ; word [ j ] = temp ; cout << word << \ndone\n ; return 0 ; John Chrispell, Wednesday 15, 2010 slide 27/27

C++ For Science and Engineering Lecture 14

C++ For Science and Engineering Lecture 14 C++ For Science and Engineering Lecture 14 John Chrispell Tulane University Monday September 27, 2010 File Input and Output Recall writing text to standard out You must include the iostream header file.

More information

C++ For Science and Engineering Lecture 8

C++ For Science and Engineering Lecture 8 C++ For Science and Engineering Lecture 8 John Chrispell Tulane University Friday 10, 2010 Arrays Structures are ways of storing more than one type of information together. A structure is a vesatile data

More information

C++ For Science and Engineering Lecture 17

C++ For Science and Engineering Lecture 17 C++ For Science and Engineering Lecture 17 John Chrispell Tulane University Monday October 4, 2010 Functions and C-Style Strings Three methods for representing the C-style string: An array of char A quoted

More information

C++ For Science and Engineering Lecture 13

C++ For Science and Engineering Lecture 13 C++ For Science and Engineering Lecture 13 John Chrispell Tulane University Wednesday September 22, 2010 Logical Expressions: Sometimes you want to use logical and and logical or (even logical not) in

More information

CS 7B - Fall Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm

CS 7B - Fall Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm CS 7B - Fall 2017 - Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm Write your responses to following questions on separate paper. Use complete sentences where appropriate and write out code

More information

CS 7B - Fall Assignment 4: Exploring Wumpus (Linked Rooms). Due 12/13/18

CS 7B - Fall Assignment 4: Exploring Wumpus (Linked Rooms). Due 12/13/18 CS 7B - Fall 2018 - Assignment 4: Exploring Wumpus (Linked Rooms). Due 12/13/18 In this project we ll build, investigate and augment the the game Hunt the Wumpus, as described in exercise 12 or PPP2, Chapter

More information

The Monte Carlo Algorithm

The Monte Carlo Algorithm The Monte Carlo Algorithm This algorithm was invented by N. Metropolis, A.W. Rosenbluth, M.N. Rosenbluth, A.H. Teller, and E. Teller, J. Chem. Phys., 21, 1087 (1953). It was listed as one of the The Top

More information

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess!

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess! The Big Picture Announcements Problem Set 9 due right now. We'll release solutions right after lecture. Congratulations you're done with CS103 problem sets! Practice final exam is Monday, December 8 from

More information

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ;

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ; CPSC 490 Input Input will always arrive on stdin. You may assume input is well-formed with respect to the problem specification; inappropriate input (e.g. text where a number was specified, number out

More information

2. Write a recursive function to add the first n terms of the alternating harmonic series:

2. Write a recursive function to add the first n terms of the alternating harmonic series: CS 7B - Spring 2014 - Midterm 2. 5/8/14 Write responses on separate paper. 1. Write a recursive method that uses only addition, subtraction, and comparison to multiply two numbers. The basic engine for

More information

Introduction to functions

Introduction to functions Introduction to functions Comp Sci 1570 Introduction to C++ Outline 1 2 Functions A function is a reusable sequence of s designed to do a particular job. In C++, a function is a group of s that is given

More information

Cluster Algorithms to Reduce Critical Slowing Down

Cluster Algorithms to Reduce Critical Slowing Down Cluster Algorithms to Reduce Critical Slowing Down Monte Carlo simulations close to a phase transition are affected by critical slowing down. In the 2-D Ising system, the correlation length ξ becomes very

More information

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess!

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess! The Big Picture Announcements Problem Set 9 due right now. We'll release solutions right after lecture. Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess! Your feedback

More information

Numerical solution of the time-independent 1-D Schrödinger equation. Matthias E. Möbius. September 24, 2010

Numerical solution of the time-independent 1-D Schrödinger equation. Matthias E. Möbius. September 24, 2010 Numerical solution of the time-independent 1-D Schrödinger equation Matthias E. Möbius September 24, 2010 1 Aim of the computational lab Numerical solution of the one-dimensional stationary Schrödinger

More information

Programsystemkonstruktion med C++: Övning 1. Karl Palmskog Translated by: Siavash Soleimanifard. September 2011

Programsystemkonstruktion med C++: Övning 1. Karl Palmskog Translated by: Siavash Soleimanifard. September 2011 Programsystemkonstruktion med C++: Övning 1 Karl Palmskog palmskog@kth.se Translated by: Siavash Soleimanifard September 2011 Programuppbyggnad Klassens uppbyggnad A C++ class consists of a declaration

More information

Session 5 (last revised: January 24, 2010) 5 1

Session 5 (last revised: January 24, 2010) 5 1 782 Session 5 (last revised: January 24, 21) 5 1 5 782 Session 5 a Follow-up to Numerical Derivative Round-Off Errors In Session 4, we looked at error plots for various ways to calculate numerical derivatives

More information

In this approach, the ground state of the system is found by modeling a diffusion process.

In this approach, the ground state of the system is found by modeling a diffusion process. The Diffusion Monte Carlo (DMC) Method In this approach, the ground state of the system is found by modeling a diffusion process. Diffusion and random walks Consider a random walk on a lattice with spacing

More information

Computational Physics (6810): Session 2

Computational Physics (6810): Session 2 Computational Physics (6810): Session 2 Dick Furnstahl Nuclear Theory Group OSU Physics Department January 13, 2017 Session 1 follow-ups Types of error Reminder of power laws Session 1 follow-ups Session

More information

Course Updates. Reminders: 1) Quiz today. 2) Written problems: 21.96, 22.6, 22.58, ) Complete Chapter 22 (all this information on web page)

Course Updates. Reminders: 1) Quiz today. 2) Written problems: 21.96, 22.6, 22.58, ) Complete Chapter 22 (all this information on web page) Course Updates http://www.phys.hawaii.edu/~varner/phy272-pr10/physics272.html Reminders: 1) Quiz today 2) Written problems: 21.96, 22.6, 22.58, 22.30 3) Complete Chapter 22 (all this information on web

More information

The Euler Method for the Initial Value Problem

The Euler Method for the Initial Value Problem The Euler Method for the Initial Value Problem http://people.sc.fsu.edu/ jburkardt/isc/week10 lecture 18.pdf... ISC3313: Introduction to Scientific Computing with C++ Summer Semester 2011... John Burkardt

More information

ACM-ICPC South Western European Regional SWERC 2008

ACM-ICPC South Western European Regional SWERC 2008 ACM-ICPC South Western European Regional SWERC 2008 FAU Contest Team icpc@i2.informatik.uni-erlangen.de Friedrich-Alexander Universität Erlangen-Nürnberg November, 23 2008 FAU Contest Team ACM-ICPC South

More information

Proving Programs Correct

Proving Programs Correct Proving Programs Correct Page 1 of 9 Proving Programs Correct How can we be sure that a piece of code does what we want it to do? One way is to try testing the code on a large group of data. Another is

More information

Comp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33

Comp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33 Comp 11 Lectures Mike Shah Tufts University July 12, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 12, 2017 1 / 33 Please do not distribute or host these slides without prior permission. Mike

More information

CS1800 Discrete Structures Spring 2018 February CS1800 Discrete Structures Midterm Version A

CS1800 Discrete Structures Spring 2018 February CS1800 Discrete Structures Midterm Version A CS1800 Discrete Structures Spring 2018 February 2018 CS1800 Discrete Structures Midterm Version A Instructions: 1. The exam is closed book and closed notes. You may not use a calculator or any other electronic

More information

Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C.

Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C. Numbers & Arithmetic Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See: P&H Chapter 2.4-2.6, 3.2, C.5 C.6 Example: Big Picture Computer System Organization and Programming

More information

NGsolve::Give me your element

NGsolve::Give me your element NGsolve::Give me your element And let your eyes delight in my ways Jay Gopalakrishnan Portland State University Winter 2015 Download code (works only on version 6.0) for these notes from here. Give me

More information

Reasoning Under Uncertainty: Introduction to Probability

Reasoning Under Uncertainty: Introduction to Probability Reasoning Under Uncertainty: Introduction to Probability CPSC 322 Uncertainty 1 Textbook 6.1 Reasoning Under Uncertainty: Introduction to Probability CPSC 322 Uncertainty 1, Slide 1 Lecture Overview 1

More information

In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and

In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows how a program can sometimes be systematically constructed

More information

Gascoigne 3D High Performance Adaptive Finite Element Toolkit

Gascoigne 3D High Performance Adaptive Finite Element Toolkit Introduction to Gascoigne 3D High Performance Adaptive Finite Element Toolkit Tutorial and manuscript by Thomas Richter thomas.richter@iwr.uni-heidelberg.de April 25, 2014 2 Contents 1 Introduction 5 1.1

More information

CS 7B - Spring Assignment: Ramsey Theory with Matrices and SFML. due 5/23/18

CS 7B - Spring Assignment: Ramsey Theory with Matrices and SFML. due 5/23/18 CS 7B - Spring 2018 - Assignment: Ramsey Theory with Matrices and SFML. due 5/23/18 Background Theory Ramsey theory, named after the British mathematician and philosopher Frank P. Ramsey, is a branch of

More information

INF 4140: Models of Concurrency Series 3

INF 4140: Models of Concurrency Series 3 Universitetet i Oslo Institutt for Informatikk PMA Olaf Owe, Martin Steffen, Toktam Ramezani INF 4140: Models of Concurrency Høst 2016 Series 3 14. 9. 2016 Topic: Semaphores (Exercises with hints for solution)

More information

Applied C Fri

Applied C Fri Applied C++11 2013-01-25 Fri Outline Introduction Auto-Type Inference Lambda Functions Threading Compiling C++11 C++11 (formerly known as C++0x) is the most recent version of the standard of the C++ Approved

More information

Naïve Bayes Lecture 6: Self-Study -----

Naïve Bayes Lecture 6: Self-Study ----- Naïve Bayes Lecture 6: Self-Study ----- Marina Santini Acknowledgements Slides borrowed and adapted from: Data Mining by I. H. Witten, E. Frank and M. A. Hall 1 Lecture 6: Required Reading Daumé III (015:

More information

Computer Science Introductory Course MSc - Introduction to Java

Computer Science Introductory Course MSc - Introduction to Java Computer Science Introductory Course MSc - Introduction to Java Lecture 1: Diving into java Pablo Oliveira ENST Outline 1 Introduction 2 Primitive types 3 Operators 4 5 Control Flow

More information

APPENDIX A FASTFLOW A.1 DESIGN PRINCIPLES

APPENDIX A FASTFLOW A.1 DESIGN PRINCIPLES APPENDIX A FASTFLOW A.1 DESIGN PRINCIPLES FastFlow 1 has been designed to provide programmers with efficient parallelism exploitation patterns suitable to implement (fine grain) stream parallel applications.

More information

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving

More information

Unit 4 Advanced Functions Review Day

Unit 4 Advanced Functions Review Day Unit 4 Advanced Functions Review Day Warm-up! Find the domain and range of the following functions. Then, tell how they are changed from their parent graph. (Hint: Remember that the order of transformations

More information

Bayesian Updating: Discrete Priors: Spring

Bayesian Updating: Discrete Priors: Spring Bayesian Updating: Discrete Priors: 18.05 Spring 2017 http://xkcd.com/1236/ Learning from experience Which treatment would you choose? 1. Treatment 1: cured 100% of patients in a trial. 2. Treatment 2:

More information

Bi-Abduction. Philippa Gardner (Imperial College London) Separation Logic 1 / 17. Bi-Abduction

Bi-Abduction. Philippa Gardner (Imperial College London) Separation Logic 1 / 17. Bi-Abduction 8 Bi-abduction and Abstraction Slide 1 In the last lecture, we saw how frame inference lets us verify that the pre- and post-conditions and loop invariants of a given program are correct. Abstraction lets

More information

Introduction to MPI. School of Computational Science, 21 October 2005

Introduction to MPI. School of Computational Science, 21 October 2005 Introduction to MPI John Burkardt School of Computational Science Florida State University... http://people.sc.fsu.edu/ jburkardt/presentations/ mpi 2005 fsu.pdf School of Computational Science, 21 October

More information

The Pip Project. PLT (W4115) Fall Frank Wallingford

The Pip Project. PLT (W4115) Fall Frank Wallingford The Pip Project PLT (W4115) Fall 2008 Frank Wallingford (frw2106@columbia.edu) Contents 1 Introduction 4 2 Original Proposal 5 2.1 Introduction....................................................... 5

More information

CSE 331 Winter 2018 Homework 1

CSE 331 Winter 2018 Homework 1 Directions: - Due Wednesday, January 10 by 11 pm. - Turn in your work online using gradescope. You should turn in a single pdf file. You can have more than one answer per page, but please try to avoid

More information

Loop Convergence. CS 536: Science of Programming, Fall 2018

Loop Convergence. CS 536: Science of Programming, Fall 2018 Solved Loop Convergence CS 536: Science of Programming, Fall 2018 A. Why Diverging programs aren t useful, so it s useful to know how to show that loops terminate. B. Objectives At the end of this lecture

More information

Lecture 24: Bloom Filters. Wednesday, June 2, 2010

Lecture 24: Bloom Filters. Wednesday, June 2, 2010 Lecture 24: Bloom Filters Wednesday, June 2, 2010 1 Topics for the Final SQL Conceptual Design (BCNF) Transactions Indexes Query execution and optimization Cardinality Estimation Parallel Databases 2 Lecture

More information

4/26/2017. More algorithms for streams: Each element of data stream is a tuple Given a list of keys S Determine which tuples of stream are in S

4/26/2017. More algorithms for streams: Each element of data stream is a tuple Given a list of keys S Determine which tuples of stream are in S Note to other teachers and users of these slides: We would be delighted if you found this our material useful in giving your own lectures. Feel free to use these slides verbatim, or to modify them to fit

More information

CSE 311: Foundations of Computing. Lecture 26: Cardinality

CSE 311: Foundations of Computing. Lecture 26: Cardinality CSE 311: Foundations of Computing Lecture 26: Cardinality Cardinality and Computability Computers as we know them grew out of a desire to avoid bugs in mathematical reasoning A brief history of reasoning

More information

B-Spline Interpolation on Lattices

B-Spline Interpolation on Lattices B-Spline Interpolation on Lattices David Eberly, Geometric Tools, Redmond WA 98052 https://www.geometrictools.com/ This work is licensed under the Creative Commons Attribution 4.0 International License.

More information

(b). Identify all basic blocks in your three address code. B1: 1; B2: 2; B3: 3,4,5,6; B4: 7,8,9; B5: 10; B6: 11; B7: 12,13,14; B8: 15;

(b). Identify all basic blocks in your three address code. B1: 1; B2: 2; B3: 3,4,5,6; B4: 7,8,9; B5: 10; B6: 11; B7: 12,13,14; B8: 15; (a). Translate the program into three address code as defined in Section 6.2, dragon book. (1) i := 2 (2) if i > n goto (7) (3) a[i] := TRUE (4) t2 := i+1 (5) i := t2 (6) goto (2) (7) count := 0 (8) s

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!

More information

Voting (Ensemble Methods)

Voting (Ensemble Methods) 1 2 Voting (Ensemble Methods) Instead of learning a single classifier, learn many weak classifiers that are good at different parts of the data Output class: (Weighted) vote of each classifier Classifiers

More information

Investigative Science PENDULUM LAB Tuesday November Perry High School Mr. Pomerantz Page 1 of 5

Investigative Science PENDULUM LAB Tuesday November Perry High School Mr. Pomerantz Page 1 of 5 Mr. Pomerantz Page 1 of 5 A swinging pendulum keeps a very regular beat. It is so regular, in fact, that for many years the pendulum was the heart of clocks used in astronomical measurements at the Greenwich

More information

Models of Computation, Recall Register Machines. A register machine (sometimes abbreviated to RM) is specified by:

Models of Computation, Recall Register Machines. A register machine (sometimes abbreviated to RM) is specified by: Models of Computation, 2010 1 Definition Recall Register Machines A register machine (sometimes abbreviated M) is specified by: Slide 1 finitely many registers R 0, R 1,..., R n, each capable of storing

More information

15 Monte Carlo methods

15 Monte Carlo methods 15 Monte Carlo methods 15.1 The Monte Carlo method The Monte Carlo method is simple, robust, and useful. It was invented by Enrico Fermi and developed by Metropolis (Metropolis et al., 1953). It has many

More information

Algorithms Exam TIN093 /DIT602

Algorithms Exam TIN093 /DIT602 Algorithms Exam TIN093 /DIT602 Course: Algorithms Course code: TIN 093, TIN 092 (CTH), DIT 602 (GU) Date, time: 21st October 2017, 14:00 18:00 Building: SBM Responsible teacher: Peter Damaschke, Tel. 5405

More information

EENG/INFE 212 Stacks

EENG/INFE 212 Stacks EENG/INFE 212 Stacks A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end called the top of the stack. A stack is a dynamic constantly

More information

Counters. We ll look at different kinds of counters and discuss how to build them

Counters. We ll look at different kinds of counters and discuss how to build them Counters We ll look at different kinds of counters and discuss how to build them These are not only examples of sequential analysis and design, but also real devices used in larger circuits 1 Introducing

More information

CSE 373: Data Structures and Algorithms. Asymptotic Analysis. Autumn Shrirang (Shri) Mare

CSE 373: Data Structures and Algorithms. Asymptotic Analysis. Autumn Shrirang (Shri) Mare CSE 373: Data Structures and Algorithms Asymptotic Analysis Autumn 2018 Shrirang (Shri) Mare shri@cs.washington.edu Thanks to Kasey Champion, Ben Jones, Adam Blank, Michael Lee, Evan McCarty, Robbie Weber,

More information

Hoare Logic and Model Checking

Hoare Logic and Model Checking Hoare Logic and Model Checking Kasper Svendsen University of Cambridge CST Part II 2016/17 Acknowledgement: slides heavily based on previous versions by Mike Gordon and Alan Mycroft Introduction In the

More information

G54FOP: Lecture 17 & 18 Denotational Semantics and Domain Theory III & IV

G54FOP: Lecture 17 & 18 Denotational Semantics and Domain Theory III & IV G54FOP: Lecture 17 & 18 Denotational Semantics and Domain Theory III & IV Henrik Nilsson University of Nottingham, UK G54FOP: Lecture 17 & 18 p.1/33 These Two Lectures Revisit attempt to define denotational

More information

CSCE 222 Discrete Structures for Computing. Review for Exam 2. Dr. Hyunyoung Lee !!!

CSCE 222 Discrete Structures for Computing. Review for Exam 2. Dr. Hyunyoung Lee !!! CSCE 222 Discrete Structures for Computing Review for Exam 2 Dr. Hyunyoung Lee 1 Strategy for Exam Preparation - Start studying now (unless have already started) - Study class notes (lecture slides and

More information

Jackson, Classical Electrodynamics, Section 14.8 Thomson Scattering of Radiation

Jackson, Classical Electrodynamics, Section 14.8 Thomson Scattering of Radiation High Energy Cross Sections by Monte Carlo Quadrature Thomson Scattering in Electrodynamics Jackson, Classical Electrodynamics, Section 14.8 Thomson Scattering of Radiation Jackson Figures 14.17 and 14.18:

More information

Computer simulation of radioactive decay

Computer simulation of radioactive decay Computer simulation of radioactive decay y now you should have worked your way through the introduction to Maple, as well as the introduction to data analysis using Excel Now we will explore radioactive

More information

Homework 6: Image Completion using Mixture of Bernoullis

Homework 6: Image Completion using Mixture of Bernoullis Homework 6: Image Completion using Mixture of Bernoullis Deadline: Wednesday, Nov. 21, at 11:59pm Submission: You must submit two files through MarkUs 1 : 1. a PDF file containing your writeup, titled

More information

EGR224 F 18 Assignment #4

EGR224 F 18 Assignment #4 EGR224 F 18 Assignment #4 ------------------------------------------------------------------------------------------------------------- Due Date: Friday (Section 10), October 19, by 5 pm (slide it under

More information

Finite State Machines. CS 447 Wireless Embedded Systems

Finite State Machines. CS 447 Wireless Embedded Systems Finite State Machines CS 447 Wireless Embedded Systems Outline Discrete systems Finite State Machines Transitions Timing Update functions Determinacy and Receptiveness 1 Discrete Systems Operates in sequence

More information

CHAPTER 13: FEEDBACK PERFORMANCE

CHAPTER 13: FEEDBACK PERFORMANCE When I complete this chapter, I want to be able to do the following. Apply two methods for evaluating control performance: simulation and frequency response Apply general guidelines for the effect of -

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION FORMAL LANGUAGES, AUTOMATA AND COMPUTATION IDENTIFYING NONREGULAR LANGUAGES PUMPING LEMMA Carnegie Mellon University in Qatar (CARNEGIE MELLON UNIVERSITY IN QATAR) SLIDES FOR 15-453 LECTURE 5 SPRING 2011

More information

(P ) Minimize 4x 1 + 6x 2 + 5x 3 s.t. 2x 1 3x 3 3 3x 2 2x 3 6

(P ) Minimize 4x 1 + 6x 2 + 5x 3 s.t. 2x 1 3x 3 3 3x 2 2x 3 6 The exam is three hours long and consists of 4 exercises. The exam is graded on a scale 0-25 points, and the points assigned to each question are indicated in parenthesis within the text. Problem 1 Consider

More information

Analysis of Algorithms. Outline 1 Introduction Basic Definitions Ordered Trees. Fibonacci Heaps. Andres Mendez-Vazquez. October 29, Notes.

Analysis of Algorithms. Outline 1 Introduction Basic Definitions Ordered Trees. Fibonacci Heaps. Andres Mendez-Vazquez. October 29, Notes. Analysis of Algorithms Fibonacci Heaps Andres Mendez-Vazquez October 29, 2015 1 / 119 Outline 1 Introduction Basic Definitions Ordered Trees 2 Binomial Trees Example 3 Fibonacci Heap Operations Fibonacci

More information

Data Structures and Algorithms Chapter 2

Data Structures and Algorithms Chapter 2 1 Data Structures and Algorithms Chapter 2 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

Oversubscribing inotify on Embedded Platforms

Oversubscribing inotify on Embedded Platforms Oversubscribing inotify on Embedded Platforms By Donald Percivalle (CPE) and Scott Vanderlind (CSC) Senior Project California Polytechnic State University San Luis Obispo Dr. Zachary Peterson June 11,

More information

SOLUTION: SOLUTION: SOLUTION:

SOLUTION: SOLUTION: SOLUTION: Convert R and S into nondeterministic finite automata N1 and N2. Given a string s, if we know the states N1 and N2 may reach when s[1...i] has been read, we are able to derive the states N1 and N2 may

More information

Path Testing and Test Coverage. Chapter 9

Path Testing and Test Coverage. Chapter 9 Path Testing and Test Coverage Chapter 9 Structural Testing Also known as glass/white/open box testing Structural testing is based on using specific knowledge of the program source text to define test

More information

Reasoning Under Uncertainty: Introduction to Probability

Reasoning Under Uncertainty: Introduction to Probability Reasoning Under Uncertainty: Introduction to Probability CPSC 322 Lecture 23 March 12, 2007 Textbook 9 Reasoning Under Uncertainty: Introduction to Probability CPSC 322 Lecture 23, Slide 1 Lecture Overview

More information

Path Testing and Test Coverage. Chapter 9

Path Testing and Test Coverage. Chapter 9 Path Testing and Test Coverage Chapter 9 Structural Testing Also known as glass/white/open box testing Structural testing is based on using specific knowledge of the program source text to define test

More information

Factorial Designs. Outline. Definition. Factorial designs. Factorial designs. Higher order interactions

Factorial Designs. Outline. Definition. Factorial designs. Factorial designs. Higher order interactions 1 Factorial Designs Outline 2 Factorial designs Conditions vs. levels Naming Why use them Main effects Interactions Simple main effect Graphical definition Additivity definition Factorial designs Independent

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!

More information

Fall 2017 Test II review problems

Fall 2017 Test II review problems Fall 2017 Test II review problems Dr. Holmes October 18, 2017 This is a quite miscellaneous grab bag of relevant problems from old tests. Some are certainly repeated. 1. Give the complete addition and

More information

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess!

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess! The Big Picture Announcements Problem Set 9 due right now. We'll release solutions right now. Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess! Your feedback really

More information

HW2 Solutions, for MATH441, STAT461, STAT561, due September 9th

HW2 Solutions, for MATH441, STAT461, STAT561, due September 9th HW2 Solutions, for MATH44, STAT46, STAT56, due September 9th. You flip a coin until you get tails. Describe the sample space. How many points are in the sample space? The sample space consists of sequences

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 X Cynthia Lee Today s topics: Performance issues in recursion Big-O performance analysis 2 Announcement: Recursive art contest! Go to http://recursivedrawing.com/ Make

More information

DARN: A Matrix Manipulation Language

DARN: A Matrix Manipulation Language DARN: A Matrix Manipulation Language Daisy Chaussee (dac2183) Anthony Kim (ak3703) Rafael Takasu (rgt2108) Ignacio (Nacho) Torras (it2216) December 20, 2016 1 Contents 1 Introduction to the Language 4

More information

PHY131H1F - Class 7. Clicker Question

PHY131H1F - Class 7. Clicker Question PHY131H1F - Class 7 Today, Chapter 4, sections 4.1-4.4: Kinematics in One Dimension Kinematics in Two Dimensions Projectile Motion Relative Motion Test Tomorrow night at 6pm [Image from http://www.nap.edu/jhp/oneuniverse/motion_22-23.html

More information

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates ECE 250 / CPS 250 Computer Architecture Basics of Logic Design Boolean Algebra, Logic Gates Benjamin Lee Slides based on those from Andrew Hilton (Duke), Alvy Lebeck (Duke) Benjamin Lee (Duke), and Amir

More information

Lecture 16: Computation Tree Logic (CTL)

Lecture 16: Computation Tree Logic (CTL) Lecture 16: Computation Tree Logic (CTL) 1 Programme for the upcoming lectures Introducing CTL Basic Algorithms for CTL CTL and Fairness; computing strongly connected components Basic Decision Diagrams

More information

CSE. 1. In following code. addi. r1, skip1 xor in r2. r3, skip2. counter r4, top. taken): PC1: PC2: PC3: TTTTTT TTTTTT

CSE. 1. In following code. addi. r1, skip1 xor in r2. r3, skip2. counter r4, top. taken): PC1: PC2: PC3: TTTTTT TTTTTT CSE 560 Practice Problem Set 4 Solution 1. In this question, you will examine several different schemes for branch prediction, using the following code sequence for a simple load store ISA with no branch

More information

Lecture 3: String Matching

Lecture 3: String Matching COMP36111: Advanced Algorithms I Lecture 3: String Matching Ian Pratt-Hartmann Room KB2.38: email: ipratt@cs.man.ac.uk 2017 18 Outline The string matching problem The Rabin-Karp algorithm The Knuth-Morris-Pratt

More information

Numerical differentiation

Numerical differentiation Chapter 3 Numerical differentiation 3.1 Introduction Numerical integration and differentiation are some of the most frequently needed methods in computational physics. Quite often we are confronted with

More information

Lecture 1: Asymptotic Complexity. 1 These slides include material originally prepared by Dr.Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole.

Lecture 1: Asymptotic Complexity. 1 These slides include material originally prepared by Dr.Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole. Lecture 1: Asymptotic Complexity 1 These slides include material originally prepared by Dr.Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole. Announcements TA office hours officially start this week see

More information

(a) Draw the coordinate system you are using and draw the free body diagram of the block during rotation with constant speed.

(a) Draw the coordinate system you are using and draw the free body diagram of the block during rotation with constant speed. 4-[25 pts.] A block of mass m is placed at the side surface of a cone. The cone can rotate about an axis through its center so that the block can make circular motion. The static friction coefficient between

More information

Outline. Approximation: Theory and Algorithms. Application Scenario. 3 The q-gram Distance. Nikolaus Augsten. Definition and Properties

Outline. Approximation: Theory and Algorithms. Application Scenario. 3 The q-gram Distance. Nikolaus Augsten. Definition and Properties Outline Approximation: Theory and Algorithms Nikolaus Augsten Free University of Bozen-Bolzano Faculty of Computer Science DIS Unit 3 March 13, 2009 2 3 Nikolaus Augsten (DIS) Approximation: Theory and

More information

6. DYNAMIC PROGRAMMING II

6. DYNAMIC PROGRAMMING II 6. DYNAMIC PROGRAMMING II sequence alignment Hirschberg's algorithm Bellman-Ford algorithm distance vector protocols negative cycles in a digraph Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison

More information

CS Deep Reinforcement Learning HW2: Policy Gradients due September 19th 2018, 11:59 pm

CS Deep Reinforcement Learning HW2: Policy Gradients due September 19th 2018, 11:59 pm CS294-112 Deep Reinforcement Learning HW2: Policy Gradients due September 19th 2018, 11:59 pm 1 Introduction The goal of this assignment is to experiment with policy gradient and its variants, including

More information

Mining Data Streams. The Stream Model Sliding Windows Counting 1 s

Mining Data Streams. The Stream Model Sliding Windows Counting 1 s Mining Data Streams The Stream Model Sliding Windows Counting 1 s 1 The Stream Model Data enters at a rapid rate from one or more input ports. The system cannot store the entire stream. How do you make

More information

Switch-Case & Break. Example 24. case 1 : p r i n t f ( January \n ) ; break ; case 2 : p r i n t f ( F e b r u a r y \n ) ; break ;

Switch-Case & Break. Example 24. case 1 : p r i n t f ( January \n ) ; break ; case 2 : p r i n t f ( F e b r u a r y \n ) ; break ; Example 24 s w i t c h ( month ) { case 1 : p r i n t f ( January \n ) ; case 2 : p r i n t f ( F e b r u a r y \n ) ; case 3 : p r i n t f ( March\n ) ; case 4 : p r i n t f ( A p r i l \n ) ; case 5

More information

f x = x x 4. Find the critical numbers of f, showing all of the

f x = x x 4. Find the critical numbers of f, showing all of the MTH 5 Winter Term 011 Test 1 - Calculator Portion Name You may hold onto this portion of the test and work on it some more after you have completed the no calculator portion of the test. On this portion

More information

ALUs and Data Paths. Subtitle: How to design the data path of a processor. 1/8/ L3 Data Path Design Copyright Joanne DeGroat, ECE, OSU 1

ALUs and Data Paths. Subtitle: How to design the data path of a processor. 1/8/ L3 Data Path Design Copyright Joanne DeGroat, ECE, OSU 1 ALUs and Data Paths Subtitle: How to design the data path of a processor. Copyright 2006 - Joanne DeGroat, ECE, OSU 1 Lecture overview General Data Path of a multifunction ALU Copyright 2006 - Joanne DeGroat,

More information

Copyright 2018 Dan Dill 1

Copyright 2018 Dan Dill 1 TP Do we get the same amount of energy back from making bonds between an ion and water molecules, as it took to break the ionic bonds holding an ion in the solid? + 1. The energy is the same 2. More energy

More information

Comp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 40

Comp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 40 Comp 11 Lectures Mike Shah Tufts University July 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 26, 2017 1 / 40 Please do not distribute or host these slides without prior permission. Mike

More information

EE16B, Spring 2018 UC Berkeley EECS. Maharbiz and Roychowdhury. Lecture 5B: Open QA Session

EE16B, Spring 2018 UC Berkeley EECS. Maharbiz and Roychowdhury. Lecture 5B: Open QA Session EE16B, Spring 2018 UC Berkeley EECS Maharbiz and Roychowdhury Lecture 5B: Open QA Session EE16B, Spring 2018, Open Q/A Session (Roychowdhury) Slide 1 Today: Open Q/A Session primarily on state space r.

More information