implement language system

Size: px
Start display at page:

Download "implement language system"

Transcription

1 Outlie Priciples of programmig laguages Lecture 3 Part I. Laguage systems Part II. Fuctioal programmig. First look at ML. Natalia Silvis-Cividjia silvis@few.vu.l vrije Uiversiteit amsterdam Imagie: A ew laguage have bee desiged ad Part I your task is to implemet this laguage. Laguage systems You have to build a laguage system Laguage systems The classical sequece The classical sequece Variatios o the classical sequece Bidig Debuggers Rutime support 1

2 1. Creatig 1. Creatig it i; void mai() { The programmer uses a editor to create a text file cotaiig the program A high-level laguage: machie idepedet 2. Compilig 2. Compilig Compiler traslates to assembly laguage Machie-specific Each lie represets either a piece of data, or a sigle machie-level istructio Programs used to be writte directly i assembly laguage, before Fortra (1957) Now used directly oly rarely it i; void mai() { C 3. Assemblig compiler assembler i: data word 0 mai: move 1 to i t1: compare i with 100 jump to t2 if greater push i call fred add 1 to i go to t1 t2: retur 2

3 3. Assemblig Assembly laguage is still ot directly executable Still text format, readable by people Still has ames, ot memory addresses Assembler coverts each assemblylaguage istructio ito the machie s biary format: its machie laguage Resultig object file ot readable by people i: data word 0 mai: move 1 to i t1: compare i with 100 jump to t2 if greater push i call fred add 1 to i go to t1 t2: retur assembler mai: i: 0 m o v e i c m i m j m p i f g p u s h i c fred a d d t i r e t u r 4. Likig 4. Likig Object file still ot directly executable Missig some parts Still has some ames Mostly machie laguage, but ot etirely Liker collects ad combies all the differet parts I our example, fred was compiled separately, ad may eve have bee writte i a differet high-level laguage Result is the executable file i: 0 mai: m o v e i c m i m mai: m o v e i c m i m j m p i f g p u s h i c fred a d d t i r e t u r liker i: 0 j m p i f g p u s h i c fred a d d t i r e t u r fred: j m p i f g r e t u r 5. Loadig 3

4 5. Loadig Executable file still ot directly executable Still has some ames Mostly machie laguage, but ot etirely Fial step: whe the program is ru, the loader loads it ito memory ad replaces ames with addresses mai: i: 0 m o v e i c m i m j m p i f g p u s h i c fred a d d t i r e t u r fred: j m p i f g r e t u r loader 0: 20: (mai) 60: (fred) 80: (i) m o v e 80 c m 80 m j m p i f g p u s h 80 c 60 a d d t 80 r e t u r j m p i f g r e t u r 0 6. Ruig 6. Ruig After loadig, the program is etirely machie laguage Processor begis executig its istructios, ad the program rus Optimizatio Usually after compilatio step Code geerated by a compiler is usually optimized to make it faster, smaller, or both First used for Fortra i 1957 Other optimizatios may be doe by the assembler, liker, ad/or loader A misomer: the resultig code is better, but ot guarateed to be optimal Example: loop ivariat removal Origial code: it i = 0; while (i < 100) { a[i++] = x*x*x; Improved code, with loop ivariat moved: it i = 0; it temp = x*x*x; while (i < 100) { a[i++] = temp; 4

5 #iclude <stdio.h> double power (double d, usiged ) { double x = 1.0; usiged j; for (j = 1; j <= ; j++) x *= d; retur x; it mai (void) { double sum = 0.0; usiged i; for (i = 1; i <= ; i++) { sum += power (i, i % 5); pritf ("sum = %g\", sum); retur 0; Laguage systems The classical sequece Variatios o the classical sequece $ gcc -Wall -O0 test.c -lm s $ gcc -Wall -O1 test.c -lm s $ gcc -Wall -O2 test.c -lm s $ gcc -Wall -O3 test.c -lm s $ gcc -Wall -O3 -furoll-loops test.c -lm s Variatios o the classical sequece The gcc C++ example Hidig steps Iterpreters Virtual machies (JVM=Java virtual machie) Delayed likig (.dll i Widows) Dyamic compilatio (JIT=just i time compilatio) Hidig steps example: the GNU C++ laguage system Laguage systems The classical sequece Variatios o the classical sequece Bidig 5

6 What is bidig? it i; void mai() { Bidig Associatio betwee two thigs (like a ame ad a property) Example: What set of values is associated with it? What is the type of fred? What is the address of the object code for mai? What is the value of i? Bidig Times 1.Laguage Desig Time Bidig time = the time whe a bidig is created (or a implemetatio decisio is made, or a aswer to a questio is give) Very importat for a laguage sematics A bidig ca happe at differet times: Laguage desig time Laguage implemetatio time Compile time Lik time Load time Rutime Some properties are boud whe the laguage is defied: Ex: Meaigs of keywords: void, for it i; void mai() { 2. Laguage Implemetatio Time Some properties are boud whe the laguage system is writte: rage of values of type it i C (but i Java, these are part of the laguage defiitio) implemetatio limitatios: max idetifier legth, max umber of array dimesios, etc it i; void mai() { 3. Compile Time Some properties are boud whe the program is compiled or prepared for iterpretatio: Types of variables, i laguages like C ad ML that use static typig Declaratio that goes with a give use of a variable, i laguages that use static scopig (most laguages) it i; void mai() { 6

7 4. Lik Time 5. Load Time Some properties are boud whe separately-compiled program parts are combied ito oe executable file by the liker: Object code for exteral fuctio ames it i; void mai() { Some properties are boud whe the program is loaded ito the computer s memory, but before it rus: Memory locatios for code for fuctios Memory locatios for static variables it i; void mai() { 6. Ru Time Practice (Exercise 3, Ch.4) Some properties are boud oly whe the code i questio is executed: Values of variables Types of variables, i laguages like Lisp that use dyamic typig Bidig at ru time is called late or dyamic bidig Bidig before ru time is called early or static! #" $ % #& ' ' ' ' ' ' # ( )$ * & # ( +, - # & * #./(, 0 & # 1 (2 $ #* ( % & ( % # )$ 3, & $ 3 # # $ & Practice (Exercise 3, Ch.4) Trade-off What is the bidig time for each of the followig i a Java program? The locatio i memory of a local variable i a method? The locatio i memory of a o-static field i a class? The meaig of the keyword while? The size i memory of a variable of type it? The type of a local variable i a fuctio? The value assiged to a variable? Rutime Rutime Laguage defiitio Laguage defiitio Compile time Ru time Early Bidig vs. Late Bidig Early: faster ad more secure at rutime (less to do, less that ca go wrog) (compilers) Late: flexible at rutime (as with types, dyamic loadig, etc.) (iterpreters) 7

8 Laguage systems Rutime Support The classical sequece Variatios o the classical sequece Bidig Debuggers Rutime support Additioal code the liker icludes eve if the program does ot refer to it explicitly Startup processig: iitializig the machie state Exceptio hadlig: reactig to exceptios Memory maagemet: allocatig memory, reusig it whe the program is fiished with it Operatig system iterface: commuicatig betwee ruig program ad operatig system for I/O, etc. A importat hidde player i laguage systems Part II Fuctioal laguages: A first look to ML Fuctioal laguages emphasize the defiitio ad applicatio of mathematical fuctios, i cotrast to imperative programmig, which emphasizes the executio of sequetial commads well-defied sematics. Make much easier to formally prove the correctess of fuctioal programs based o lambda calculus Examples: Lisp, ML, Scheme, Haskell, Mirada Read more about : Discussios forum: comp.lag.fuctioal y = f(x) * f(x) Ca you say it is the same with: z = f(x) y = z*z ;? About ML ML=Meta Laguage used for a theorem prover Ediburgh, 1974, Robi Miler s group There are a umber of dialects We are usig Stadard ML (istalled o Liux machies) Good book: Ulma, Elemets of ML programmig Aother popular dialect is OCaml = Objective Caml (used by Ileidig i Theoretische Iformatica) 8

9 Gettig started To ru SML i iteractive mode, type to the Uix prompt $sml Type a expressio after - prompt; ML replies with value ad type Do t forget ; after the expressio! Variable it is a special variable that is boud to the value of the expressio you type Stadard ML of New Jersey - 1+2*3; val it = 7 : it Outlie Costats Operators Variables Tuples ad Lists Fuctios Costats ; val it = 1234 : it ; val it = : real - true; - "fred"; val it = "fred" : strig - "H"; val it = "H" : strig - #"H"; val it = #"H" : char ML is case-sesitive it : Iteger costats: real : Real costats bool: Boolea costats true ad false strig: Strig costats: text iside double quotes char: Character costats: put # before a 1-character strig Operators -~ * 4 div 5 mod 6; val it = ~1 : it - ~ * 4.0 / 5.0; val it = ~1.4 : real -"bibity" ^ "bobity" ^ "boo"; val it = "bibitybobityboo" : strig Stadard operators for itegers, usig ~ for uary egatio ad - for biary subtractio Same operators for reals, but use / for divisio Strig cocateatio: ^ operator Left associative, precedece is {+,- < {*,/,div,mod < {~. Orderig operators - 2 < 3; <= 1.0; - #"d" > #"c"; - "abce" >= "abd"; val it = false : bool Orderig comparisos: <, >, <=, >=, apply to strig, char, it ad real Order o strigs ad characters is lexicographic Equality compariso operators - 1 = 2; val it = false : bool - true <> false; = 1.3; Error: operator ad operad do't agree [equality type required] operator domai: ''Z * ''Z operad: real * real i expressio: 1.3 = 1.3 Most types are equality testable: these are equality types Type real is ot a equality type 9

10 Boolea operators Short circuitig operators - 1 < 2 orelse 3 > 4; - 1 < 2 adalso ot (3 < 4); val it = false : bool Boolea operators: adalso, orelse, ot. (Ad we ca also use = for equivalece ad <> for exclusive or.) Precedece so far: {orelse < {adalso < {=,<>,<,>,<=,>= < {+,-,^ < {*,/,div,mod < {~,ot - true orelse 1 div 0 = 0; adalso ad orelse are short-circuitig operators = if the first operad of orelse is true, the secod is ot evaluated; likewise if the first operad of adalso is false Coditioal expressios - if 1 < 2 the #"x" else #"y"; val it = #"x" : char - if 1 > 2 the 34 else 56; val it = 56 : it - (if 1 < 2 the 34 else 56) + 1; val it = 35 : it Coditioal expressio (ot statemet) usig if the else Similar to C's terary operator: (1<2)? 'x' : 'y' Value of the expressio is the value of the the part, if the test part is true, or the value of the else part otherwise There is o if the costruct Overloaded operators - 1 * 2; val it = 2 : it * 2.0; val it = 2.0 : real * 2; Error: operator ad operad do't agree [literal] operator domai: real * real operad: real * it i expressio: 1.0 * 2 The * operator, ad others like + ad <, are overloaded to have oe meaig o pairs of itegers, ad aother o pairs of reals Type coversios A little about fuctios ML does ot perform implicit type coversio ML has builti coversio fuctios: real (it to real), floor (real to it), ceil (real to it), roud (real to it), truc (real to it), ord (char to it), chr (it to char), str (char to strig) - real(123); val it = : real - floor(3.6); val it = 3 : it - floor 3.6; val it = 3 : it - str #"a"; val it = "a" : strig - square 2+1; val it = 5 : it - square (2+1); val it = 9 : it Fuctio applicatio has higher precedece tha ay operator Fuctio applicatio is leftassociative 10

11 Defiig variables - val x = 1+2*3; val x = 7 : it - x; val it = 7 : it - val y = if x = 7 the 1.0 else 2.0; val y = 1.0 : real val creates a bidig val defies a ew variable ad bids it to a value. ML has No assigmet val defiitio i ML is ot the same as assigmet i C or Java. val defies a ew variable ad bids it to a value BUT it does ot chage the old defiitio. It adds a ew defiitio op top of the other. - val radius = 4.0; val radius = 4.0 : real - radius; val it = 4.0 : real - val radius = 5.0; val radius = 5.0 : real - radius; val it = 5.0 : real Fuctios have o side effects -val x = 0 ; val x=0; it -fu ic(x) = x+1 ; val ic = f : it -> it - ic x; val it = 1 : it - ic x; val it = 1 : it The value of x is ot chaged by the fuctio = referetial trasparecy Tuples Tuple = collectio of values of differet types (like barey,poit1) Tuples ca cotai other tuples To get i'th elemet of a tuple x, use #i x There is o such thig as a tuple of oe - val barey = (1+2, 3.0*4.0, "brow"); val barey = (3,12.0,"brow") : it * real * strig - val poit1 = ("red", (300,200)); val poit1 = ("red",(300,200)) : strig * (it * it) - #2 barey; val it = 12.0 : real - #1 (#2 poit1); val it = 300 : it Tuple Type Costructor ML gives the type of a tuple usig * as a type costructor For example, it * bool is the type of pairs (x,y) where x is a it ad y is a bool Note that paretheses have structural sigificace here: it * (it * bool) is ot the same as (it * it) * bool, ad either is the same as it * it * bool Lists List = collectio of values of the same type -[1,2,3]; val it = [1,2,3] : it list - [1.0,2.0]; val it = [1.0,2.0] : real list - [(1,2),(1,3)]; val it = [(1,2),(1,3)] : (it * it) list - [[1,2,3],[1,2]]; val it = [[1,2,3],[1,2]] : it list list - []; val it = [] : 'a list - il; val it = [] : 'a list Empty list is [] or il. The type of the empty list is 'a list 'a list meas a list of elemets, type ukow 11

12 The ull test - ull []; - ull [1,2,3]; val it = false : bool ull tests whether a give list is empty You could also use a equality test, as i x = [] However, ull x is preferred; we will see why i a momet List Type Costructor ML gives the type of lists usig list as a type costructor For example, it list is the type of lists of thigs, each of which is of type it A list is ot a tuple operator cocateates 2 lists of the same type - [1,2,3]@[4,5,6]; val it = [1,2,3,4,5,6] : it list List-builder (cos) operator is :: It takes a elemet of ay type, ad a list of elemets of that same type, ad produces a ew list by puttig the ew elemet o the frot of the old list - val x = #"c"::[]; val x = [#"c"] : char list - val y = #"b"::x; val y = [#"b",#"c"] : char list - val z = 1::2::3::[]; val z = [1,2,3] : it list The :: operator is right-associative The hd fuctio gets the head of a list: the first elemet The tl fuctio gets the tail of a list: the whole list after the first elemet The explode fuctio coverts a strig to a list of characters, ad the implode fuctio does the reverse - hd z; val it = 1 : it - tl z; val it = [2,3] : it list - tl(tl z); val it = [3] : it list - tl(tl(tl z)); val it = [] : it list - explode "hello"; val it = [#"h",#"e",#"l",#"l",#"o"] : char list - implode [#"h",#"i"]; val it = "hi" : strig Defiig fuctios - fu firstchar s = hd (explode s); val firstchar = f : strig -> char - firstchar "abc"; val it = #"a" : char fu defies a ew fuctio ad bids it to a variable Here f meas a fuctio, the thig itself, cosidered separately from ay ame we've give it. The value of firstchar is a fuctio whose type is strig -> char Fuctio Defiitio Sytax <fu-def> ::= fu <fuctio-ame> <parameter> = <expressio> ; <fuctio-ame> ca be ay legal ML ame The simplest <parameter> is just a sigle variable ame: the formal parameter of the fuctio The <expressio> is ay ML expressio; its value is the value the fuctio returs This is oly a subset of ML fuctio defiitio sytax; 12

13 Fuctio Type Costructor ML gives the type of fuctios usig -> as a type costructor For example, it -> real is the type of a fuctio that takes a it parameter (the domai type) ad produces a real result (the rage type) - fu quot(a,b) = a div b; val quot = f : it * it -> it - quot (6,2); val it = 3 : it - val pair = (6,2); val pair = (6,2) : it * it - quot pair; val it = 3 : it All ML fuctios take exactly oe parameter To pass more tha oe thig, you ca pass a tuple Example 1 - fu fact = = if = 0 the 1 = else * fact(-1); val fact = f : it -> it - fact 5; val it = 120 : it Recursive factorial fuctio Example 2 - fu listsum x = = if ull x the 0 = else hd x + listsum(tl x); val listsum = f : it list -> it - listsum [1,2,3,4,5]; val it = 15 : it Recursive fuctio to add up the elemets of a it list A commo patter: base case for ull x, recursive call o tl x Example 3 - fu legth x = = if ull x the 0 = else 1 + legth (tl x); val legth = f : 'a list -> it - legth [true,false,true]; val it = 3 : it - legth [4.0,3.0,2.0,1.0]; val it = 4 : it Recursive fuctio to compute the legth of a list Note type: this works o ay type of list. It is polymorphic. - fu badlegth x = = if x=[] the 0 = else 1 + badlegth (tl x); val badlegth = f : ''a list -> it - badlegth [true,false,true]; val it = 3 : it - badlegth [4.0,3.0,2.0,1.0]; Error: operator ad operad do't agree [equality type required] Same as previous example, but with x=[] istead of ull x Type variables that begi with two apostrophes, like ''a, are restricted to equality types. ML isists o that restrictio because we compared x for equality with the empty list. That s why you should use ull x istead of x=[]. It avoids uecessary type restrictios. 13

14 Example 4 - fu reverse L = = if ull L the il = else reverse(tl [hd L]; val reverse = f : 'a list -> 'a list - reverse [1,2,3]; val it = [3,2,1] : it list Recursive fuctio to reverse a list That patter agai Summary Costats ad primitive types: it, real, bool, char, strig Operators: ~, +, -, *, div, mod, /, ^, <, >, <=, >=, =, <>, ot, adalso, orelse Coditioal expressio Fuctio applicatio Predefied fuctios: real, floor, ceil, roud, truc, ord, chr, str, hd, tl, explode, implode, ad ull Summary, Cotiued Defiig ew variable bidigs usig val Tuple costructio usig (x,y,,z) ad selectio usig # List costructio usig [x,y,,z] Type costructors *, list, ad -> Fuctio declaratio usig fu It s easy; it s fu All real programmig i ML is coducted by defiitio of fuctios ad applicatio of these fuctios to argumets. Fuctioal laguages are also called applicative laguages Practice What is the value ad ML type for each of these expressios? 1 * * 4 "abc" ^ "def" if (1 < 2) the 3.0 else < 2 orelse (1 div 0) = 0 What is wrog with each of these expressios? 10 / 5 #"a" = #"b" or 1 = = 1.0 if (1<2) the 3 Practice Suppose we make these ML declaratios: val a = "123"; val b = "456"; val c = a ^ b ^ "789"; val a = 3 + 4; The what is the value ad type of each of these expressios? a b c 14

15 Practice What are the values of these expressios? #2(3,4,5) hd(1::2::il) hd(tl(#2([1,2],[3,4]))); What is wrog with the followig expressios? hd(tl(tl [1,2])) [1]::[2,3] 15

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1 A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

More information

CS 11 C track: lecture 1

CS 11 C track: lecture 1 CS 11 C track: lecture 1 Prelimiaries Need a CMS cluster accout http://acctreq.cms.caltech.edu/cgi-bi/request.cgi Need to kow UNIX IMSS tutorial liked from track home page Track home page: http://courses.cms.caltech.edu/courses/cs11/material

More information

From last week. Lecture 5. Outline. Principles of programming languages

From last week. Lecture 5. Outline. Principles of programming languages Priciples of programmig laguages From last week Lecture 5 http://few.vu.l/~silvis/ppl/2007 Natalia Silvis-Cividjia e-mail: silvis@few.vu.l ML has o assigmet. Explai how to access a old bidig? Is & for

More information

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen COP4020 mig Laguages Compilers ad Iterpreters Prof. Robert va Egele Overview Commo compiler ad iterpreter cofiguratios Virtual machies Itegrated developmet eviromets Compiler phases Lexical aalysis Sytax

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programmig Laguages Fuctioal Programmig Prof. Robert va Egele Overview What is fuctioal programmig? Historical origis of fuctioal programmig Fuctioal programmig today Cocepts of fuctioal programmig

More information

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 1 Computers ad Programs 1 Objectives To uderstad the respective roles of hardware ad software i a computig system. To lear what computer scietists

More information

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion Aoucemets HW6 due today HW7 is out A team assigmet Submitty page will be up toight Fuctioal correctess: 75%, Commets : 25% Last class Equality testig eq? vs. equal? Higher-order fuctios map, foldr, foldl

More information

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Itroductio to Computers ad C++ Programmig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 1.1 Computer Systems 1.2 Programmig ad Problem Solvig 1.3 Itroductio to C++ 1.4 Testig

More information

CMPT 125 Assignment 2 Solutions

CMPT 125 Assignment 2 Solutions CMPT 25 Assigmet 2 Solutios Questio (20 marks total) a) Let s cosider a iteger array of size 0. (0 marks, each part is 2 marks) it a[0]; I. How would you assig a poiter, called pa, to store the address

More information

n Haskell n Syntax n Lazy evaluation n Static typing and type inference n Algebraic data types n Pattern matching n Type classes

n Haskell n Syntax n Lazy evaluation n Static typing and type inference n Algebraic data types n Pattern matching n Type classes Aoucemets Quiz 7 HW 9 is due o Friday Raibow grades HW 1-6 plus 8. Please, read our commets o 8! Exam 1-2 Quiz 1-6 Ay questios/cocers, let us kow ASAP Last Class Haskell Sytax Lazy evaluatio Static typig

More information

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 9 Poiters ad Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 9.1 Poiters 9.2 Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 9-3

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to

More information

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1 COSC 1P03 Ch 7 Recursio Itroductio to Data Structures 8.1 COSC 1P03 Recursio Recursio I Mathematics factorial Fiboacci umbers defie ifiite set with fiite defiitio I Computer Sciece sytax rules fiite defiitio,

More information

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions CS 111: Program Desig I Lecture # 7: First Loop, Web Crawler, Fuctios Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago September 18, 2018 What will this prit? x = 5 if x == 3: prit("hi!")

More information

Elementary Educational Computer

Elementary Educational Computer Chapter 5 Elemetary Educatioal Computer. Geeral structure of the Elemetary Educatioal Computer (EEC) The EEC coforms to the 5 uits structure defied by vo Neuma's model (.) All uits are preseted i a simplified

More information

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers? CSE401: Itroductio to Compiler Costructio Larry Ruzzo Sprig 2004 Today s objectives Admiistrative details Defie compilers ad why we study them Defie the high-level structure of compilers Associate specific

More information

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 2.1 Variables ad Assigmets 2.2 Iput ad Output 2.3 Data Types ad Expressios 2.4 Simple Flow of Cotrol 2.5 Program

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4

More information

n Haskell n Covered syntax, lazy evaluation, static typing n Algebraic data types and pattern matching n Type classes n Monads and more n Types

n Haskell n Covered syntax, lazy evaluation, static typing n Algebraic data types and pattern matching n Type classes n Monads and more n Types Aoucemets Exam 2 is graded, but I will eed some time to go over it I ll release grades this eveig (figers crossed!) Raibow grades: HW1-6, Exam 1-2, Quiz 1-5 Will post aswer key Still gradig: Quiz 6, HW7

More information

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strigs ad Vectors Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3 8.1 A Array Type for Strigs A Array Type for Strigs C-strigs ca be used to represet strigs

More information

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June CS 1313 010: Programmig for No-Majors, Summer 2007 Programmig Project #3: Two Little Calculatios Due by 12:00pm (oo) Wedesday Jue 27 2007 This third assigmet will give you experiece writig programs that

More information

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types Aoucemets HW9 due today HW10 comig up, will post after class Team assigmet Data abstractio (types) ad cotrol abstractio (parameter passig) Due o Tuesday, November 27 th Last Class Types Type systems Type

More information

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1 Classes ad Objects jvo@ualg.pt José Valete de Oliveira 4-1 Agai: Distace betwee poits withi the first quadrat Sample iput Sample output 1 1 3 4 2 jvo@ualg.pt José Valete de Oliveira 4-2 1 The simplest

More information

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Pseudocode ( 1.1) High-level descriptio of a algorithm More structured

More information

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis Itro to Algorithm Aalysis Aalysis Metrics Slides. Table of Cotets. Aalysis Metrics 3. Exact Aalysis Rules 4. Simple Summatio 5. Summatio Formulas 6. Order of Magitude 7. Big-O otatio 8. Big-O Theorems

More information

Goals of the Lecture Object Constraint Language

Goals of the Lecture Object Constraint Language Goals of the Lecture Object Costrait Laguage Object-Orieted Aalysis ad Desig - Fall 1998 Preset the Object Costrait Laguage Ð As best as possible, with the limited iformatio available from UML i a Nutshell

More information

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 8 Strigs ad Vectors Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Copyright 2015 Pearso Educatio, Ltd..

More information

BaanERP Tools. Programming features

BaanERP Tools. Programming features BaaERP Tools A publicatio of: Baa Developmet B.V. P.O.Box 143 3770 AC Bareveld The Netherlads Prited i the Netherlads Baa Developmet B.V. 1998. All rights reserved. The iformatio i this documet is subject

More information

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen COP4020 Programmig Laguages Subrouties ad Parameter Passig Prof. Robert va Egele Overview Parameter passig modes Subroutie closures as parameters Special-purpose parameters Fuctio returs COP4020 Fall 2016

More information

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70 NOTE:. Attempt all seve questios. Major CSL 02 2. Write your ame ad etry o o every sheet of the aswer script. Time 2 Hrs Max Marks 70 Q No Q Q 2 Q 3 Q 4 Q 5 Q 6 Q 7 Total MM 6 2 4 0 8 4 6 70 Q. Write a

More information

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts CS 111 Gree: Program Desig I Lecture 27: Speed (cot.); partig thoughts By Nascarkig - Ow work, CC BY-SA 4.0, https://commos.wikimedia.org/w/idex.php?curid=38671041 Robert H. Sloa (CS) & Rachel Poretsky

More information

n Bottom-up (LR) parsing n Characteristic Finite State Machine (CFSM) n SLR(1) parsing table n Conflicts in SLR(1) n LR parsing variants

n Bottom-up (LR) parsing n Characteristic Finite State Machine (CFSM) n SLR(1) parsing table n Conflicts in SLR(1) n LR parsing variants Aoucemets Gradig HW1 Should be doe by the ed of today. Grades are set to release toight You have 1 week to issue re-grade request Raibow grades comig up over the weeked Last Class Bottom-up (LR) parsig

More information

Java Expressions & Flow Control

Java Expressions & Flow Control Java Expressios & Flow Cotrol Rui Moreira Expressio Separators:. [ ] ( ), ; Dot used as decimal separator or to access attributes ad methods double d = 2.6; Poto poto = ew Poto(2, 3); it i = poto.x; it

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures Uiversity of Waterloo Departmet of Electrical ad Computer Egieerig ECE 250 Algorithms ad Data Structures Midterm Examiatio ( pages) Istructor: Douglas Harder February 7, 2004 7:30-9:00 Name (last, first)

More information

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup   Note: Chapter 4 Computatio Bjare Stroustrup www.stroustrup.com/programmig Abstract Today, I ll preset the basics of computatio. I particular, we ll discuss expressios, how to iterate over a series of values

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 18 Strategies for Query Processig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio DBMS techiques to process a query Scaer idetifies

More information

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output File class i Java File Iput ad Output TOPICS File Iput Exceptio Hadlig File Output Programmers refer to iput/output as "I/O". The File class represets files as objects. The class is defied i the java.io

More information

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer Departmet of Computer ciece Columbia Uiversity olutios to Fial COM W45 Programmig Laguages ad Traslators Moday, May 4, 2009 4:0-5:25pm, 309 Havemeyer Closed book, o aids. Do questios 5. Each questio is

More information

Behavioral Modeling in Verilog

Behavioral Modeling in Verilog Behavioral Modelig i Verilog COE 202 Digital Logic Desig Dr. Muhamed Mudawar Kig Fahd Uiversity of Petroleum ad Mierals Presetatio Outlie Itroductio to Dataflow ad Behavioral Modelig Verilog Operators

More information

. Written in factored form it is easy to see that the roots are 2, 2, i,

. Written in factored form it is easy to see that the roots are 2, 2, i, CMPS A Itroductio to Programmig Programmig Assigmet 4 I this assigmet you will write a java program that determies the real roots of a polyomial that lie withi a specified rage. Recall that the roots (or

More information

High-Order Language APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL

High-Order Language APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL Chapter 2 C High-Order Laguage APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL 6 ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL MICROCODE LEVEL LOGIC GATE LEVEL Figure 2. 7 6 5 4

More information

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis Outlie ad Readig Aalysis of Algorithms Iput Algorithm Output Ruig time ( 3.) Pseudo-code ( 3.2) Coutig primitive operatios ( 3.3-3.) Asymptotic otatio ( 3.6) Asymptotic aalysis ( 3.7) Case study Aalysis

More information

Baan Tools User Management

Baan Tools User Management Baa Tools User Maagemet Module Procedure UP008A US Documetiformatio Documet Documet code : UP008A US Documet group : User Documetatio Documet title : User Maagemet Applicatio/Package : Baa Tools Editio

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Ruig Time of a algorithm Ruig Time Upper Bouds Lower Bouds Examples Mathematical facts Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite

More information

Computers and Scientific Thinking

Computers and Scientific Thinking Computers ad Scietific Thikig David Reed, Creighto Uiversity Chapter 15 JavaScript Strigs 1 Strigs as Objects so far, your iteractive Web pages have maipulated strigs i simple ways use text box to iput

More information

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide CS11 Fall 003 Prelim Solutios ad Gradig Guide Problem 1: (a) obj = obj1; ILLEGAL because type of referece must always be a supertype of type of object (b) obj3 = obj1; ILLEGAL because type of referece

More information

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design College of Computer ad Iformatio Scieces Departmet of Computer Sciece CSC 220: Computer Orgaizatio Uit 11 Basic Computer Orgaizatio ad Desig 1 For the rest of the semester, we ll focus o computer architecture:

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 19 Query Optimizatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio Query optimizatio Coducted by a query optimizer i a DBMS Goal:

More information

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000. 5-23 The course that gives CM its Zip Memory Maagemet II: Dyamic Storage Allocatio Mar 6, 2000 Topics Segregated lists Buddy system Garbage collectio Mark ad Sweep Copyig eferece coutig Basic allocator

More information

Lecture 1: Introduction and Strassen s Algorithm

Lecture 1: Introduction and Strassen s Algorithm 5-750: Graduate Algorithms Jauary 7, 08 Lecture : Itroductio ad Strasse s Algorithm Lecturer: Gary Miller Scribe: Robert Parker Itroductio Machie models I this class, we will primarily use the Radom Access

More information

top() Applications of Stacks

top() Applications of Stacks CS22 Algorithms ad Data Structures MW :00 am - 2: pm, MSEC 0 Istructor: Xiao Qi Lecture 6: Stacks ad Queues Aoucemets Quiz results Homework 2 is available Due o September 29 th, 2004 www.cs.mt.edu~xqicoursescs22

More information

Programming with Shared Memory PART II. HPC Spring 2017 Prof. Robert van Engelen

Programming with Shared Memory PART II. HPC Spring 2017 Prof. Robert van Engelen Programmig with Shared Memory PART II HPC Sprig 2017 Prof. Robert va Egele Overview Sequetial cosistecy Parallel programmig costructs Depedece aalysis OpeMP Autoparallelizatio Further readig HPC Sprig

More information

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects. The

More information

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 5 Fuctios for All Subtasks Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 5.1 void Fuctios 5.2 Call-By-Referece Parameters 5.3 Usig Procedural Abstractio 5.4 Testig ad Debuggig

More information

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis Overview Chapter 6 Writig a Program Bjare Stroustrup Some thoughts o software developmet The idea of a calculator Usig a grammar Expressio evaluatio Program orgaizatio www.stroustrup.com/programmig 3 Buildig

More information

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time ( 3.1) Aalysis of Algorithms Iput Algorithm Output A algorithm is a step- by- step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects.

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Ruig Time Most algorithms trasform iput objects ito output objects. The

More information

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software Structurig Redudacy for Fault Tolerace CSE 598D: Fault Tolerat Software What do we wat to achieve? Versios Damage Assessmet Versio 1 Error Detectio Iputs Versio 2 Voter Outputs State Restoratio Cotiued

More information

COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen

COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen COP4020 Programmig Laguages Names, Scopes, ad Bidigs Prof. Robert va Egele Overview Abstractios ad ames Bidig time Object lifetime Object storage maagemet Static allocatio Stack allocatio Heap allocatio

More information

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013 Code Review s Authors: Mika V. Mätylä ad Casper Lasseius Origial versio: 4 Sep, 2007 Made available olie: 24 April, 2013 This documet cotais further details of the code review defects preseted i [1]. of

More information

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames Uit 4, Part 3 Recursio Computer Sciece S-111 Harvard Uiversity David G. Sulliva, Ph.D. Review: Method Frames Whe you make a method call, the Java rutime sets aside a block of memory kow as the frame of

More information

condition w i B i S maximum u i

condition w i B i S maximum u i ecture 10 Dyamic Programmig 10.1 Kapsack Problem November 1, 2004 ecturer: Kamal Jai Notes: Tobias Holgers We are give a set of items U = {a 1, a 2,..., a }. Each item has a weight w i Z + ad a utility

More information

Data Structures and Algorithms. Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms Data Structures ad Algorithms Aalysis of Algorithms Outlie Ruig time Pseudo-code Big-oh otatio Big-theta otatio Big-omega otatio Asymptotic algorithm aalysis Aalysis of Algorithms Iput Algorithm Output

More information

Linked Lists 11/16/18. Preliminaries. Java References. Objects and references. Self references. Linking self-referential nodes

Linked Lists 11/16/18. Preliminaries. Java References. Objects and references. Self references. Linking self-referential nodes Prelimiaries Liked Lists public class StrageObject { Strig ame; StrageObject other; Arrays are ot always the optimal data structure: A array has fixed size eeds to be copied to expad its capacity Addig

More information

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 10 Defiig Classes Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types 10.4 Itroductio to Iheritace Copyright 2015 Pearso Educatio,

More information

COMP Parallel Computing. PRAM (1): The PRAM model and complexity measures

COMP Parallel Computing. PRAM (1): The PRAM model and complexity measures COMP 633 - Parallel Computig Lecture 2 August 24, 2017 : The PRAM model ad complexity measures 1 First class summary This course is about parallel computig to achieve high-er performace o idividual problems

More information

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering EE 4363 1 Uiversity of Miesota Midterm Exam #1 Prof. Matthew O'Keefe TA: Eric Seppae Departmet of Electrical ad Computer Egieerig Uiversity of Miesota Twi Cities Campus EE 4363 Itroductio to Microprocessors

More information

Ones Assignment Method for Solving Traveling Salesman Problem

Ones Assignment Method for Solving Traveling Salesman Problem Joural of mathematics ad computer sciece 0 (0), 58-65 Oes Assigmet Method for Solvig Travelig Salesma Problem Hadi Basirzadeh Departmet of Mathematics, Shahid Chamra Uiversity, Ahvaz, Ira Article history:

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13 CIS Data Structures ad Algorithms with Java Sprig 08 Stacks ad Queues Moday, February / Tuesday, February Learig Goals Durig this lab, you will: Review stacks ad queues. Lear amortized ruig time aalysis

More information

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence _9.qxd // : AM Page Chapter 9 Sequeces, Series, ad Probability 9. Sequeces ad Series What you should lear Use sequece otatio to write the terms of sequeces. Use factorial otatio. Use summatio otatio to

More information

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1 CS200: Hash Tables Prichard Ch. 13.2 CS200 - Hash Tables 1 Table Implemetatios: average cases Search Add Remove Sorted array-based Usorted array-based Balaced Search Trees O(log ) O() O() O() O(1) O()

More information

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015. Presetatio for use with the textbook Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Hash Tables xkcd. http://xkcd.com/221/. Radom Number. Used with permissio uder Creative

More information

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then UCLA PIC 10 B Problem Solvig usig C++ Programmig Ivo Diov, Asst. Prof. i Mathematics, Neurology, Statistics Istructor: Teachig Assistat: Suzae Nezzar, Mathematics Chapter 13 Templates for More Abstractio

More information

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS) CSC165H1, Witer 018 Learig Objectives By the ed of this worksheet, you will: Aalyse the ruig time of fuctios cotaiig ested loops. 1. Nested loop variatios. Each of the followig fuctios takes as iput a

More information

Module 8-7: Pascal s Triangle and the Binomial Theorem

Module 8-7: Pascal s Triangle and the Binomial Theorem Module 8-7: Pascal s Triagle ad the Biomial Theorem Gregory V. Bard April 5, 017 A Note about Notatio Just to recall, all of the followig mea the same thig: ( 7 7C 4 C4 7 7C4 5 4 ad they are (all proouced

More information

Lecture 1. Topics. Principles of programming languages (2007) Lecture 1. What makes programming languages such an interesting subject?

Lecture 1. Topics. Principles of programming languages (2007) Lecture 1. What makes programming languages such an interesting subject? Priciples of programmig laguages (2007) Lecture 1 http://few.vu.l/~silvis/ppl/2007 Natalia Silvis-Cividjia e-mail: silvis@few.vu.l Lecture 1. Topics Studet survey Itroductio History of major programmig

More information

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access CS 111: Program Desig I Lecture # 7: Web Crawler, Fuctios; Ope Access Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago September 13, 2016 Lab Hit/Remider word = "hi" word.upper() à "HI" Questio

More information

Lecture 9: Exam I Review

Lecture 9: Exam I Review CS 111 (Law): Program Desig I Lecture 9: Exam I Review Robert H. Sloa & Richard Warer Uiversity of Illiois, Chicago September 22, 2016 This Class Discuss midterm topics Go over practice examples Aswer

More information

Package RcppRoll. December 22, 2014

Package RcppRoll. December 22, 2014 Type Package Package RcppRoll December 22, 2014 Title Fast rollig fuctios through Rcpp ad RcppArmadillo Versio 0.1.0 Date 2013-01-10 Author Kevi Ushey Maitaier Kevi Ushey RcppRoll

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 26 Ehaced Data Models: Itroductio to Active, Temporal, Spatial, Multimedia, ad Deductive Databases Copyright 2016 Ramez Elmasri ad Shamkat B.

More information

Chapter 4 The Datapath

Chapter 4 The Datapath The Ageda Chapter 4 The Datapath Based o slides McGraw-Hill Additioal material 24/25/26 Lewis/Marti Additioal material 28 Roth Additioal material 2 Taylor Additioal material 2 Farmer Tae the elemets that

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19 CIS Data Structures ad Algorithms with Java Sprig 09 Stacks, Queues, ad Heaps Moday, February 8 / Tuesday, February 9 Stacks ad Queues Recall the stack ad queue ADTs (abstract data types from lecture.

More information

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists CS 111: Program Desig I Lecture 16: Module Review, Ecodigs, Lists Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 18, 2016 Last time Dot otatio ad methods Padas: user maual poit

More information

One advantage that SONAR has over any other music-sequencing product I ve worked

One advantage that SONAR has over any other music-sequencing product I ve worked *gajedra* D:/Thomso_Learig_Projects/Garrigus_163132/z_productio/z_3B2_3D_files/Garrigus_163132_ch17.3d, 14/11/08/16:26:39, 16:26, page: 647 17 CAL 101 Oe advatage that SONAR has over ay other music-sequecig

More information

The isoperimetric problem on the hypercube

The isoperimetric problem on the hypercube The isoperimetric problem o the hypercube Prepared by: Steve Butler November 2, 2005 1 The isoperimetric problem We will cosider the -dimesioal hypercube Q Recall that the hypercube Q is a graph whose

More information

Τεχνολογία Λογισμικού

Τεχνολογία Λογισμικού ΕΘΝΙΚΟ ΜΕΤΣΟΒΙΟ ΠΟΛΥΤΕΧΝΕΙΟ Σχολή Ηλεκτρολόγων Μηχανικών και Μηχανικών Υπολογιστών Τεχνολογία Λογισμικού, 7ο/9ο εξάμηνο 2018-2019 Τεχνολογία Λογισμικού Ν.Παπασπύρου, Αν.Καθ. ΣΗΜΜΥ, ickie@softlab.tua,gr

More information

Examples and Applications of Binary Search

Examples and Applications of Binary Search Toy Gog ITEE Uiersity of Queeslad I the secod lecture last week we studied the biary search algorithm that soles the problem of determiig if a particular alue appears i a sorted list of iteger or ot. We

More information

CSE 111 Bio: Program Design I Class 11: loops

CSE 111 Bio: Program Design I Class 11: loops SE 111 Bio: Program Desig I lass 11: loops Radall Muroe, xkcd.com/1411/ Robert H. Sloa (S) & Rachel Poretsky (Bio) Uiversity of Illiois, hicago October 2, 2016 Pytho ets Loopy! he Pytho, Busch ardes Florida

More information

Reliable Transmission. Spring 2018 CS 438 Staff - University of Illinois 1

Reliable Transmission. Spring 2018 CS 438 Staff - University of Illinois 1 Reliable Trasmissio Sprig 2018 CS 438 Staff - Uiversity of Illiois 1 Reliable Trasmissio Hello! My computer s ame is Alice. Alice Bob Hello! Alice. Sprig 2018 CS 438 Staff - Uiversity of Illiois 2 Reliable

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions: CS 604 Data Structures Midterm Sprig, 00 VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Istructios: Prit your ame i the space provided below. This examiatio is closed book ad closed

More information

A graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n))

A graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n)) ca see that time required to search/sort grows with size of We How do space/time eeds of program grow with iput size? iput. time: cout umber of operatios as fuctio of iput Executio size operatio Assigmet:

More information

Inductive Definition to Recursive Function

Inductive Definition to Recursive Function PDS: CS 11002 Computer Sc & Egg: IIT Kharagpur 1 Iductive Defiitio to Recursive Fuctio PDS: CS 11002 Computer Sc & Egg: IIT Kharagpur 2 Factorial Fuctio Cosider the followig recursive defiitio of the factorial

More information

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov Sortig i Liear Time Data Structures ad Algorithms Adrei Bulatov Algorithms Sortig i Liear Time 7-2 Compariso Sorts The oly test that all the algorithms we have cosidered so far is compariso The oly iformatio

More information

CMSC Computer Architecture Lecture 3: ISA and Introduction to Microarchitecture. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 3: ISA and Introduction to Microarchitecture. Prof. Yanjing Li University of Chicago CMSC 22200 Computer Architecture Lecture 3: ISA ad Itroductio to Microarchitecture Prof. Yajig Li Uiversity of Chicago Lecture Outlie ISA uarch (hardware implemetatio of a ISA) Logic desig basics Sigle-cycle

More information

Homework 1 Solutions MA 522 Fall 2017

Homework 1 Solutions MA 522 Fall 2017 Homework 1 Solutios MA 5 Fall 017 1. Cosider the searchig problem: Iput A sequece of umbers A = [a 1,..., a ] ad a value v. Output A idex i such that v = A[i] or the special value NIL if v does ot appear

More information

Data Structures and Algorithms Part 1.4

Data Structures and Algorithms Part 1.4 1 Data Structures ad Algorithms Part 1.4 Werer Nutt 2 DSA, Part 1: Itroductio, syllabus, orgaisatio Algorithms Recursio (priciple, trace, factorial, Fiboacci) Sortig (bubble, isertio, selectio) 3 Sortig

More information

CS 111: Program Design I Lecture 15: Modules, Pandas again. Robert H. Sloan & Richard Warner University of Illinois at Chicago March 8, 2018

CS 111: Program Design I Lecture 15: Modules, Pandas again. Robert H. Sloan & Richard Warner University of Illinois at Chicago March 8, 2018 CS 111: Program Desig I Lecture 15: Modules, Padas agai Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago March 8, 2018 PYTHON STANDARD LIBRARY & BEYOND: MODULES Extedig Pytho Every moder

More information

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016 CS 111: Program Desig I Lecture 15: Objects, Padas, Modules Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 13, 2016 OBJECTS AND DOT NOTATION Objects (Implicit i Chapter 2, Variables,

More information

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Single-Cycle Disadvantages & Advantages

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Single-Cycle Disadvantages & Advantages COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter 4 The Processor Pipeliig Sigle-Cycle Disadvatages & Advatages Clk Uses the clock cycle iefficietly the clock cycle must

More information