C++ For Science and Engineering Lecture 17
|
|
- Silas Booth
- 6 years ago
- Views:
Transcription
1 C++ For Science and Engineering Lecture 17 John Chrispell Tulane University Monday October 4, 2010
2 Functions and C-Style Strings Three methods for representing the C-style string: An array of char A quoted sttring constant (or string literal) A pointer-to-char set to the address of the string A three are type pointer to char (or type char *), and work as arguments to string-processing functions. char ghost [ 1 5 ] = g a l l o p i n g ; char s t r = galumphing ; i n t n1 = s t r l e n ( ghost ) ; // ghost i s &ghost [ 0 ] i n t n2 = s t r l e n ( s t r ) ; // p o i n t e r to char i n t n3 = s t r l e n ( gamboling ) ; // a d d r e s s o f s t r i n g In all cases you ar passing a string as an argument, or more accurately you ar passing the address of the first character in the string. John Chrispell, Monday October 4, 2010 slide 3/15
3 Functions and C-Style Strings Remember that C-style strings have a terminating NULL character built in that makes them distinct from plain character arrays. This allows functions to loop over the elements in the C-style string and find the terminating character. Consider the following user defined function. It can be used to count the number of times a specific character is in string. / ================================================ / / This f u n c t i o n c o u n t s the number o f ch c h a r a c t e r s / / i n the s t r i n g s t r / / ================================================ / i n t c i n s t r ( const char s t r, char ch ){ i n t count = 0 ; while ( s t r ){ // q u i t when s t r i s \0 i f ( s t r == ch ){ count++; s t r ++; // move p o i n t e r to next char return count ; A main function is given in the next listing: John Chrispell, Monday October 4, 2010 slide 5/15
4 strgfun.cpp #include <iostream > i n t c i n s t r ( const char s t r, char ch ) ; // i n t c i n s t r ( c o n s t char s t r [ ], char ch ) ; // 2nd p r o t o t y p e. using namespace s t d ; char mmm[ 1 5 ] = minimum ; // s t r i n g i n an a r r a y char w a i l = u l u l a t e ; // w a i l p o i n t s to s t r i n g i n t ms = c i n s t r (mmm, m ) ; i n t us = c i n s t r ( w a i l, u ) ; cout << ms << m c h a r a c t e r s i n << mmm << e n d l ; cout << us << u c h a r a c t e r s i n << w a i l << e n d l ; Joke from text: Why are string processing functions so ruthless? John Chrispell, Monday October 4, 2010 slide 7/15
5 strgfun.cpp #include <iostream > i n t c i n s t r ( const char s t r, char ch ) ; // i n t c i n s t r ( c o n s t char s t r [ ], char ch ) ; // 2nd p r o t o t y p e. using namespace s t d ; char mmm[ 1 5 ] = minimum ; // s t r i n g i n an a r r a y char w a i l = u l u l a t e ; // w a i l p o i n t s to s t r i n g i n t ms = c i n s t r (mmm, m ) ; i n t us = c i n s t r ( w a i l, u ) ; cout << ms << m c h a r a c t e r s i n << mmm << e n d l ; cout << us << u c h a r a c t e r s i n << w a i l << e n d l ; Joke from text: Why are string processing functions so ruthless? Because they stop at nothing. The next example returns a C-style string. John Chrispell, Monday October 4, 2010 slide 7/15
6 strgback.cpp #include <iostream > char b u i l d s t r ( char c, i n t n ) ; // p r o t o t y p e i n t times ; char ch ; cout << Enter a character : ; c i n >> ch ; cout << Enter an i n t e g e r : ; c i n >> times ; char ps = b u i l d s t r ( ch, t i m e s ) ; cout << ps << endl ; delete [ ] ps ; // f r e e memory / Later we w i l l learn about classes and destructors / / That w i l l take care of memory deallocation for us / ps = bui lds tr ( +, 20); // reuse pointer cout << ps << DONE << ps << endl ; delete [ ] ps ; // f r e e memory char buil dst r ( char c, i n t n ){ char p s t r = new char [ n + 1 ] ; p s t r [ n ] = \0 ; // t e r m i n a t e s t r i n g while ( n > 0){ p s t r [ n ] = c ; // f i l l r e s t o f s t r i n g return pstr ; John Chrispell, Monday October 4, 2010 slide 9/15
7 Passing Structurs to Programs. Lets first consider treating a structure like we would a simple type: (like int, or double). We define a simple struct: s t r u c t t r a v e l t i m e { i n t hours ; i n t mins ; A basic prototype for a function of this sort is: t r a v e l t i m e sum ( t r a v e l t i m e t1, t r a v e l t i m e t2 ) ; A simple function that uses these is: John Chrispell, Monday October 4, 2010 slide 11/15
8 travel.cpp #include <iostream > s t r u c t travel time { i n t hours ; i n t mins ; ; const i n t M i n s p e r h r = 6 0 ; t r a v e l t i m e sum ( t r a v e l t i m e t1, t r a v e l t i m e t2 ) ; void show time ( t r a v e l t i m e t ) ; travel time day1 = {5, 45; // 5 hrs, 45 min travel time day2 = {4, 55; // 4 hrs, 55 min t r a v e l t i m e t r i p = sum ( day1, day2 ) ; cout << Two day t o t a l : ; show time ( t r i p ) ; t r a v e l t i m e day3= {4, 32; cout << Three day t o t a l : ; show time (sum ( t r i p, day3 ) ) ; t r a v e l t i m e sum ( t r a v e l t i m e t1, t r a v e l t i m e t2 ){ t r a v e l t i m e t o t a l ; t o t a l. mins = ( t1. mins + t2. mins ) % M i n s p e r h r ; t o t a l. hours = t1. hours + t2. hours + ( t1. mins + t2. mins ) / M i n s p e r h r ; return t o t a l ; void show time ( travel time t ){ cout << t. hours << hours, << t. mins << minutes \n ; John Chrispell, Monday October 4, 2010 slide 13/15
9 strctfun.cpp #i n c lude <iostream > #i n c lude <cmath> / s t r u c t u r e d e c l a r a t i o n s / s t r u c t p o l a r { double distance ; // distance from o r i g i n double angle ; // d i r e c t i o n from o r i g i n ; s t r u c t r e c t { double x ; // h o r i z o n t a l d i s t a n c e from o r i g i n double y ; // v e r t i c a l d i s t a n c e from o r i g i n ; / p r o t o t y p e s / p o l a r r e c t t o p o l a r ( r e c t xypos ) ; void s h o w p o l a r ( p o l a r dapos ) ; re c t r pl a c e ; p o l a r pplace ; cout << Enter the x and y values : ; while ( cin >> r pl ac e. x >> r pl ac e. y ) // s l i c k use of cin { pplace = r e c t t o p o l a r ( r p l a c e ) ; s h o w p o l a r ( p p l a c e ) ; cout << Next two numbers (q to quit ) : ; cout << Done. \ n ; / c o n v e r t r e c t a n g u l a r to p o l a r c o o r d i n a t e s / p o l a r r e c t t o p o l a r ( r e c t xypos ){ p o l a r answer ; answer. d i s t a n c e = s q r t ( xypos. x xypos. x + xypos. y xypos. y ) ; answer. a n g l e = atan2 ( xypos.y, xypos. x ) ; return answer ; // r e t u r n s a p o l a r s t r u c t u r e / show polar coordinates, converting angle to degrees / void s h o w p o l a r ( p o l a r dapos ){ const double Rad to deg = ; cout << d i s t a n c e = << dapos. d i s t a n c e ; cout <<, a n g l e = << dapos. a n g l e Rad to deg ; cout << d e g r e e s \n ; John Chrispell, Monday October 4, 2010 slide 15/15
10 strctptr.cpp It is also possible to pass structs by address. This is useful if you want to update the contents, or initialize them. #include <iostream > #include <cmath> s t r u c t p o l a r { double distance ; // distance from o r i g i n double angle ; // d i r e c t i o n from o r i g i n ; s t r u c t r e c t { double x ; // h o r i z o n t a l d i s t a n c e from o r i g i n double y ; // v e r t i c a l d i s t a n c e from o r i g i n ; // p r o t o t y p e s void r e c t t o p o l a r ( const r e c t pxy, p o l a r pda ) ; void s h o w p o l a r ( const p o l a r pda ) ; re c t r pl a c e ; p o l a r pplace ; cout << Enter the x and y values : ; while ( cin >> r pl ac e. x >> r pl ac e. y ){ r e c t t o p o l a r (& rplace, &pplace ) ; // pass addresses show polar (& pplace ) ; // pass address cout << Next two numbers (q to quit ) : ; cout << Done. \ n ; / show polar coordinates, converting angle to degrees / void s h o w p o l a r ( const p o l a r pda ){ const double Rad to deg = ; cout << distance = << pda >distance ; cout <<, angle = << pda >angle Rad to deg ; cout << d e g r e e s \n ; / c o n v e r t r e c t a n g u l a r to p o l a r c o o r d i n a t e s / void r e c t t o p o l a r ( const r e c t pxy, p o l a r pda ){ pda >d i s t a n c e = s q r t ( pxy >x pxy >x + pxy >y pxy >y ) ; pda >a n g l e = atan2 ( pxy >y, pxy >x ) ; John Chrispell, Monday October 4, 2010 slide 17/15
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 informationC++ For Science and Engineering Lecture 10
C++ For Science and Engineering Lecture 10 John Chrispell Tulane University Wednesday 15, 2010 Introducing for loops Often we want programs to do the same action more than once. #i n c l u d e
More informationC++ 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 informationC++ 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 informationCS 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 informationComp 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 informationCongratulations 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 informationCS 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 informationThe 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 informationIntroduction 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 informationComp 11 Lectures. Mike Shah. June 20, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 20, / 38
Comp 11 Lectures Mike Shah Tufts University June 20, 2017 Mike Shah (Tufts University) Comp 11 Lectures June 20, 2017 1 / 38 Please do not distribute or host these slides without prior permission. Mike
More informationNumerical 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 informationCS 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 informationNumerical 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 informationCS 221 Lecture 9. Tuesday, 1 November 2011
CS 221 Lecture 9 Tuesday, 1 November 2011 Some slides in this lecture are from the publisher s slides for Engineering Computation: An Introduction Using MATLAB and Excel 2009 McGraw-Hill Today s Agenda
More informationIn 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 informationCluster 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 information2. 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 informationimport 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 informationCongratulations 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 informationITI 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 informationINTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.
C PROGRAMMING 1 INTRODUCTION This is not a full c-programming course. It is not even a full 'Java to c' programming course. 2 LITTERATURE 3. 1 FOR C-PROGRAMMING The C Programming Language (Kernighan and
More informationITI 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 informationConstructors - Cont. must be distinguished by the number or type of their arguments.
Constructors - Cont. 1 Constructors can be overloaded! must be distinguished by the number or type of their arguments. 2 When no constructor is defined, there is a default constructor with no arguments.
More informationIntro to Theory of Computation
Intro to Theory of Computation LECTURE 9 Last time: Converting a PDA to a CFG Pumping Lemma for CFLs Today: Pumping Lemma for CFLs Review of CFGs/PDAs Sofya Raskhodnikova 2/9/2016 Sofya Raskhodnikova;
More informationString Matching II. Algorithm : Design & Analysis [19]
String Matching II Algorithm : Design & Analysis [19] In the last class Simple String Matching KMP Flowchart Construction Jump at Fail KMP Scan String Matching II Boyer-Moore s heuristics Skipping unnecessary
More informationComputation Theory Finite Automata
Computation Theory Dept. of Computing ITT Dublin October 14, 2010 Computation Theory I 1 We would like a model that captures the general nature of computation Consider two simple problems: 2 Design a program
More informationNatural Language Processing Prof. Pushpak Bhattacharyya Department of Computer Science & Engineering, Indian Institute of Technology, Bombay
Natural Language Processing Prof. Pushpak Bhattacharyya Department of Computer Science & Engineering, Indian Institute of Technology, Bombay Lecture - 21 HMM, Forward and Backward Algorithms, Baum Welch
More informationComp 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 informationApplied 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 informationSearching. Constant time access. Hash function. Use an array? Better hash function? Hash function 4/18/2013. Chapter 9
Constant time access Searching Chapter 9 Linear search Θ(n) OK Binary search Θ(log n) Better Can we achieve Θ(1) search time? CPTR 318 1 2 Use an array? Use random access on a key such as a string? Hash
More informationSolutions. 9. Ans. C. Memory size. 11. Ans. D. a b c d e f a d e b c f a b d c e f a d b c e f a b d e c f a d b e c f. 13. Ans. D. Merge sort n log n
Solutions. Ans. B. ~ p q ~ r ~ s ~ p q r s ~ ~ p q r s p ~ q r s ~ p q ~ r v ~ s For x only the above compound preposition is true.. Ans. B. Case I First bit is 0 Case II First bit is 6. Ans. A. # has
More informationMolecular Dynamics Simulation of Argon
Molecular Dynamics Simulation of Argon The fundamental work on this problem was done by A. Rahman, Phys. Rev. 136, A405 (1964). It was extended in many important ways by L. Verlet, Phys. Rev. 159, 98 (1967),
More informationNotater: INF3331. Veronika Heimsbakk December 4, Introduction 3
Notater: INF3331 Veronika Heimsbakk veronahe@student.matnat.uio.no December 4, 2013 Contents 1 Introduction 3 2 Bash 3 2.1 Variables.............................. 3 2.2 Loops...............................
More informationNGsolve::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 informationLecture on Sensor Networks
Lecture on Sensor Networks Cyclic Historical Redundancy Development Copyright (c) 2008 Dr. Thomas Haenselmann (University of Mannheim, Germany). Permission is granted to copy, distribute and/or modify
More informationA Simple Implementation Technique for Priority Search Queues
A Simple Implementation Technique for Priority Search Queues RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/ April,
More informationMechanized Operational Semantics
Mechanized Operational Semantics J Strother Moore Department of Computer Sciences University of Texas at Austin Marktoberdorf Summer School 2008 (Lecture 5: Boyer-Moore Fast String Searching) 1 The Problem
More informationCS100: DISCRETE STRUCTURES
1 CS100: DISCRETE STRUCTURES Computer Science Department Lecture 2: Functions, Sequences, and Sums Ch2.3, Ch2.4 2.3 Function introduction : 2 v Function: task, subroutine, procedure, method, mapping, v
More informationSession 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 informationProgramsystemkonstruktion 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 information4.4 The Calendar program
4.4. THE CALENDAR PROGRAM 109 4.4 The Calendar program To illustrate the power of functions, in this section we will develop a useful program that allows the user to input a date or a month or a year.
More informationCS 7B - Spring Assignment: Adapting the calculator for bitwise expressions. due 2/21/18
CS 7B - Spring 2018 - Assignment: Adapting the calculator for bitwise expressions. due 2/21/18 Background Theory A bitwise number is a number in base 2. In base 2, place values are either a 1 or 0, depending
More informationENS Lyon Camp. Day 5. Basic group. C October
ENS Lyon Camp. Day 5. Basic group. C++. 30 October Contents 1 Input/Output 1 1.1 C-style.......................................... 1 1. C++-style........................................ Stack Overflow
More informationNested Differentiation and Symmetric Hessian Graphs with ADTAGEO
Nested Differentiation and Symmetric Hessian Graphs with ADTAGEO ADjoints and TAngents by Graph Elimination Ordering Jan Riehme Andreas Griewank Institute for Applied Mathematics Humboldt Universität zu
More informationComputational Models Lecture 8 1
Computational Models Lecture 8 1 Handout Mode Nachum Dershowitz & Yishay Mansour. Tel Aviv University. May 17 22, 2017 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice
More informationComputational Models Lecture 8 1
Computational Models Lecture 8 1 Handout Mode Ronitt Rubinfeld and Iftach Haitner. Tel Aviv University. May 11/13, 2015 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice
More informationTuring Machines Part III
Turing Machines Part III Announcements Problem Set 6 due now. Problem Set 7 out, due Monday, March 4. Play around with Turing machines, their powers, and their limits. Some problems require Wednesday's
More informationTuring Machines Part II
Turing Machines Part II Problem Set Set Five Five due due in in the the box box up up front front using using a late late day. day. Hello Hello Condensed Slide Slide Readers! Readers! This This lecture
More informationProject 4/5 - Molecular dynamics part II: advanced study of Lennard-Jones fluids, deadline December 1st (noon)
Format for delivery of report and programs The format of the project is that of a printed file or hand-written report. The programs should also be included with the report. Write only your candidate number
More informationBinary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016
Binary Search Trees Lecture 29 Section 19.2 Robb T. Koether Hampden-Sydney College Fri, Apr 8, 2016 Robb T. Koether (Hampden-Sydney College) Binary Search Trees Fri, Apr 8, 2016 1 / 40 1 Binary Search
More informationExample problem: Adaptive solution of the 2D advection diffusion equation
Chapter 1 Example problem: Adaptive solution of the 2D advection diffusion equation In this example we discuss the adaptive solution of the 2D advection-diffusion problem Solve Two-dimensional advection-diffusion
More informationPHP Extension Development with C++
PHP Extension Development with C++ Wrapping a C preprocessor API in C++ Florian Sowade August 25, 2012 About Me Florian Sowade Head of embedded software development at crosscan GmbH Currently studying
More informationInsert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park
1617 Preview Data Structure Review COSC COSC Data Structure Review Linked Lists Stacks Queues Linked Lists Singly Linked List Doubly Linked List Typical Functions s Hash Functions Collision Resolution
More informationCOMS 6100 Class Notes
COMS 6100 Class Notes Daniel Solus September 20, 2016 1 General Remarks The Lecture notes submitted by the class have been very good. Integer division seemed to be a common oversight when working the Fortran
More informationE23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101
E23: Hotel Management System Author: 1302509 Zhao Ruimin 1301478 Wen Yunlu 1302575 Hu Xing 1301911 Chen Ke 1302599 Tang Haoyuan Module: EEE 101 Lecturer: Date: Dr.Lin December/22/2014 Contents Contents
More informationSolutions. Prelim 2[Solutions]
Prelim [Solutions]. Short Answer [ pts] (a) [ pts] A traversal of an expression tree produces the string + + 3. i. What kind of traversal is it? Preorder; the operator is printed before the operands. ii.
More informationComputer 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 informationStructural Induction
Structural Induction In this lecture we ll extend the applicability of induction to many universes, ones where we can define certain kinds of objects by induction, in addition to proving their properties
More informationTuring Machines Part Two
Turing Machines Part Two Recap from Last Time Our First Turing Machine q acc a start q 0 q 1 a This This is is the the Turing Turing machine s machine s finiteisttiteiconntont. finiteisttiteiconntont.
More informationRecursion. Recursion. Steven Zeil. November 25, 2013
Steven Zeil November 25, 2013 Outline 1 2 Example: Compressing a Picture 3 Outline I 1 2 Example: Compressing a Picture 3 A function is recursive if it calls itself or calls some other function that eventually
More informationLecture 5: The Shift-And Method
Biosequence Algorithms, Spring 2005 Lecture 5: The Shift-And Method Pekka Kilpeläinen University of Kuopio Department of Computer Science BSA Lecture 5: Shift-And p.1/19 Seminumerical String Matching Most
More informationName Solutions Linear Algebra; Test 3. Throughout the test simplify all answers except where stated otherwise.
Name Solutions Linear Algebra; Test 3 Throughout the test simplify all answers except where stated otherwise. 1) Find the following: (10 points) ( ) Or note that so the rows are linearly independent, so
More informationCS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)
CS5371 Theory of Computation Lecture 7: Automata Theory V (CFG, CFL, CNF) Announcement Homework 2 will be given soon (before Tue) Due date: Oct 31 (Tue), before class Midterm: Nov 3, (Fri), first hour
More informationDATA MINING LECTURE 6. Similarity and Distance Sketching, Locality Sensitive Hashing
DATA MINING LECTURE 6 Similarity and Distance Sketching, Locality Sensitive Hashing SIMILARITY AND DISTANCE Thanks to: Tan, Steinbach, and Kumar, Introduction to Data Mining Rajaraman and Ullman, Mining
More informationHere is a sample problem that shows you how to use two different methods to add twodimensional
LAB 2 VECTOR ADDITION-METHODS AND PRACTICE Purpose : You will learn how to use two different methods to add vectors. Materials: Scientific calculator, pencil, unlined paper, protractor, ruler. Discussion:
More informationMore Dynamic Programming
Algorithms & Models of Computation CS/ECE 374, Fall 2017 More Dynamic Programming Lecture 14 Tuesday, October 17, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 48 What is the running time of the following?
More informationComputational Models Lecture 8 1
Computational Models Lecture 8 1 Handout Mode Ronitt Rubinfeld and Iftach Haitner. Tel Aviv University. April 18/ May 2, 2016 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice
More informationMotivation. Dictionaries. Direct Addressing. CSE 680 Prof. Roger Crawfis
Motivation Introduction to Algorithms Hash Tables CSE 680 Prof. Roger Crawfis Arrays provide an indirect way to access a set. Many times we need an association between two sets, or a set of keys and associated
More informationTuring Machines. Our most powerful model of a computer is the Turing Machine. This is an FA with an infinite tape for storage.
Turing Machines Our most powerful model of a computer is the Turing Machine. This is an FA with an infinite tape for storage. A Turing Machine A Turing Machine (TM) has three components: An infinite tape
More informationDiscrete-event simulations
Discrete-event simulations Lecturer: Dmitri A. Moltchanov E-mail: moltchan@cs.tut.fi http://www.cs.tut.fi/kurssit/elt-53606/ OUTLINE: Why do we need simulations? Step-by-step simulations; Classifications;
More informationLecture 10: The Normal Distribution. So far all the random variables have been discrete.
Lecture 10: The Normal Distribution 1. Continuous Random Variables So far all the random variables have been discrete. We need a different type of model (called a probability density function) for continuous
More informationIntroduction to Programming (Java) 3/12
Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction
More informationINF421, Lecture 2 Queues
INF421, Lecture 2 Queues Leo Liberti LIX, École Polytechnique, France INF421, Lecture 2 p. 1 Course Objective: to teach you some data structures and associated algorithms Evaluation: TP noté en salle info
More informationIntro to Theory of Computation
Intro to Theory of Computation LECTURE 15 Last time Decidable languages Designing deciders Today Designing deciders Undecidable languages Diagonalization Sofya Raskhodnikova 3/1/2016 Sofya Raskhodnikova;
More informationUnit 8: Sequ. ential Circuits
CPSC 121: Models of Computation Unit 8: Sequ ential Circuits Based on slides by Patrice Be lleville and Steve Wolfman Pre-Class Learning Goals By the start of class, you s hould be able to Trace the operation
More informationSection 4.1 The Power Method
Section 4.1 The Power Method Key terms Dominant eigenvalue Eigenpair Infinity norm and 2-norm Power Method Scaled Power Method Power Method for symmetric matrices The notation used varies a bit from that
More informationCS 591, Lecture 6 Data Analytics: Theory and Applications Boston University
CS 591, Lecture 6 Data Analytics: Theory and Applications Boston University Babis Tsourakakis February 8th, 2017 Universal hash family Notation: Universe U = {0,..., u 1}, index space M = {0,..., m 1},
More informationCPSC 490 Problem Solving in Computer Science
CPSC 490 Problem Solving in Computer Science Lecture 6: Recovering Solutions from DP, Bitmask DP, Matrix Exponentiation David Zheng and Daniel Du Based on CPSC490 slides from 2014-2017 2018/01/23 Announcements
More informationPrelim 2[Solutions] Solutions. 1. Short Answer [18 pts]
Prelim [Solutions]. Short Answer [8 pts] (a) [3 pts] In a model/view/controller, Swing is likely to be part of (there may be more than one): i. the model ii. the view iii. the controller The view and the
More informationData Structures and Algorithms Winter Semester
Page 0 German University in Cairo December 26, 2015 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher Dr. Wael Abouelsadaat Data Structures and Algorithms Winter Semester 2015-2016 Final
More information(pp ) PDAs and CFGs (Sec. 2.2)
(pp. 117-124) PDAs and CFGs (Sec. 2.2) A language is context free iff all strings in L can be generated by some context free grammar Theorem 2.20: L is Context Free iff a PDA accepts it I.e. if L is context
More informationIntroduction to Computing II (ITI 1121) FINAL EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification
More informationSE 3310b Theoretical Foundations of Software Engineering. Turing Machines. Aleksander Essex
SE 3310b Theoretical Foundations of Software Engineering Turing Machines Aleksander Essex 1 / 1 Turing Machines 2 / 1 Introduction We ve finally arrived at a complete model of computation: Turing machines.
More informationRunning Time Evaluation
Running Time Evaluation Quadratic Vs. Linear Time Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 19 1 Running time 2 Examples 3 Big-Oh, Big-Omega, and Big-Theta Tools 4 Time
More informationAPPENDIX 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 information6. 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 informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 5 Greedy Algorithms Interval Scheduling Interval Partitioning Guest lecturer: Martin Furer Review In a DFS tree of an undirected graph, can there be an edge (u,v)
More informationStephen Scott.
1 / 27 sscott@cse.unl.edu 2 / 27 Useful for modeling/making predictions on sequential data E.g., biological sequences, text, series of sounds/spoken words Will return to graphical models that are generative
More informationOutline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University
COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying
More informationMathematics for Decision Making: An Introduction. Lecture 8
Mathematics for Decision Making: An Introduction Lecture 8 Matthias Köppe UC Davis, Mathematics January 29, 2009 8 1 Shortest Paths and Feasible Potentials Feasible Potentials Suppose for all v V, there
More informationScripting Languages Fast development, extensible programs
Scripting Languages Fast development, extensible programs Devert Alexandre School of Software Engineering of USTC November 30, 2012 Slide 1/60 Table of Contents 1 Introduction 2 Dynamic languages A Python
More informationCS213d Data Structures and Algorithms
CS21d Data Structures and Algorithms Heaps and their Applications Milind Sohoni IIT Bombay and IIT Dharwad March 22, 2017 1 / 18 What did I see today? March 22, 2017 2 / 18 Heap-Trees A tree T of height
More informationSupplementary Material
Supplementary Material Contents 1 Keywords of GQL 2 2 The GQL grammar 3 3 THE GQL user guide 4 3.1 The environment........................................... 4 3.2 GQL projects.............................................
More informationCS481F01 Solutions 6 PDAS
CS481F01 Solutions 6 PDAS A. Demers 2 November 2001 1. Give a NPDAs that recognize the following languages: (a) The set of all strings in {0, 1} that contain twice as many 1s as 0s. (answer a) We build
More informationFoundations of Natural Language Processing Lecture 6 Spelling correction, edit distance, and EM
Foundations of Natural Language Processing Lecture 6 Spelling correction, edit distance, and EM Alex Lascarides (Slides from Alex Lascarides and Sharon Goldwater) 2 February 2019 Alex Lascarides FNLP Lecture
More informationTuring Machine Variants
CS311 Computational Structures Turing Machine Variants Lecture 12 Andrew Black Andrew Tolmach 1 The Church-Turing Thesis The problems that can be decided by an algorithm are exactly those that can be decided
More informationProgramming 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 informationOutline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.
Outline CS21 Decidability and Tractability Lecture 5 January 16, 219 and Languages equivalence of NPDAs and CFGs non context-free languages January 16, 219 CS21 Lecture 5 1 January 16, 219 CS21 Lecture
More informationCSE 105 THEORY OF COMPUTATION
CSE 105 THEORY OF COMPUTATION "Winter" 2018 http://cseweb.ucsd.edu/classes/wi18/cse105-ab/ Today's learning goals Sipser Ch 4.2 Trace high-level descriptions of algorithms for computational problems. Use
More information