COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Size: px
Start display at page:

Download "COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen"

Transcription

1 COP4020 Programmig Laguages Fuctioal Programmig Prof. Robert va Egele

2 Overview What is fuctioal programmig? Historical origis of fuctioal programmig Fuctioal programmig today Cocepts of fuctioal programmig Fuctioal programmig with Scheme Lear (more by example COP4020 Fall

3 What is Fuctioal Programmig? Fuctioal programmig is a declarative programmig style (programmig paradigm Pro: flow of computatio is declarative, i.e. more implicit Pro: promotes buildig more complex fuctios from other fuctios that serve as buildig blocks (compoet reuse Pro: behavior of fuctios defied by the values of iput argumets oly (o side-effects via global/static variables Cos: fuctio compositio is (cosidered to be stateless Cos: programmers prefer imperative programmig costructs such as statemet sequecig, while fuctioal laguages emphasize fuctio compositio COP4020 Fall

4 Cocepts of Fuctioal Programmig Pure fuctioal programmig defies the outputs of a program purely as a fuctio of the iputs with o otio of iteral state (o side effects A pure fuctio ca be couted o to retur the same output each time we ivoke it with the same iput parameter values No global (statically allocated variables No explicit (poiter assigmets Daglig poiters ad u-iitialized variables caot occur! Example pure fuctioal programmig laguages: Mirada, Haskell, ad Sisal No-pure fuctioal programmig laguages iclude imperative features that cause side effects (e.g. destructive assigmets to global variables or assigmets/chages to lists ad data structures Example: Lisp, Scheme, ad ML COP4020 Fall

5 Fuctioal Laguage Costructs Buildig blocks are fuctios No statemet compositio Fuctio compositio No variable assigmets But: ca use local variables to hold a value assiged oce No loops Recursio List comprehesios i Mirada ad Haskell But: do-loops i Scheme Coditioal flow with if-the-else or argumet patters Fuctioal laguages are statically (Haskell or dyamically (Lisp typed Haskell examples: gcd a b a == b = a a > b = gcd (a-b b a < b = gcd a (b-a fac 0 = 1 fac = * fac (-1 member x [] = false member x (y:xs x == y = true x <> y = member x xs COP4020 Fall

6 Theory ad Origi of Fuctioal Laguages Church's thesis: All models of computatio are equally powerful Turig's model of computatio: Turig machie Readig/writig of values o a ifiite tape by a fiite state machie Church's model of computatio: Lambda Calculus Fuctioal programmig laguages implemet Lambda Calculus Computability theory A program ca be viewed as a costructive proof that some mathematical object with a desired property exists A fuctio is a mappig from iputs to output objects ad computes output objects from appropriate iputs For example, the propositio that every pair of oegative itegers (the iputs has a greatest commo divisor (the output object has a costructive proof implemeted by Euclid's algorithm writte as a "fuctio" COP4020 Fall

7 Impact of Fuctioal Laguages o Laguage Desig Useful features are foud i fuctioal laguages that are ofte missig i procedural laguages or have bee adopted by moder programmig laguages: First-class fuctio values: the ability of fuctios to retur ewly costructed fuctios Higher-order fuctios: fuctios that take other fuctios as iput parameters or retur fuctios Polymorphism: the ability to write fuctios that operate o more tha oe type of data Aggregate costructs for costructig structured objects: the ability to specify a structured object i-lie such as a complete list or record value Garbage collectio COP4020 Fall

8 Fuctioal Programmig Today Sigificat improvemets i theory ad practice of fuctioal programmig have bee made i recet years Strogly typed (with type iferece Modular Sugarig: imperative laguage features that are automatically traslated to fuctioal costructs (e.g. loops by recursio Improved efficiecy Remaiig obstacles to fuctioal programmig: Social: most programmers are traied i imperative programmig ad are t used to thik i terms of fuctio compositio Commercial: ot may libraries, ot very portable, ad o IDEs COP4020 Fall

9 Applicatios May (commercial applicatios are built with fuctioal programmig laguages based o the ability to maipulate symbolic data more easily Examples: Computer algebra (e.g. Reduce system Natural laguage processig Artificial itelligece Automatic theorem provig Algorithmic optimizatio of fuctioal programs COP4020 Fall

10 LISP ad Scheme The origial fuctioal laguage ad implemetatio of Lambda Calculus Lisp ad dialects (Scheme, commo Lisp are still the most widely used fuctioal laguages Simple ad elegat desig of Lisp: Homogeeity of programs ad data: a Lisp program is a list ad ca be maipulated i Lisp as a list Self-defiitio: a Lisp iterpreter ca be writte i Lisp Iteractive: user iteractio via "read-eval-prit" loop COP4020 Fall

11 Scheme Scheme is a popular Lisp dialect Lisp ad Scheme adopt a form of prefix otatio called Cambridge Polish otatio Scheme is case isesitive A Scheme expressio is composed of Atoms, e.g. a literal umber, strig, or idetifier ame, Lists, e.g. '(a b c Fuctio ivocatios writte i list otatio: the first list elemet is the fuctio (or operator followed by the argumets to which it is applied: (fuctio arg 1 arg 2 arg 3... arg For example, si(x*x+1 is writte as (si (+ (* x x 1 COP4020 Fall

12 Read-Eval-Prit The "Read-eval-prit" loop provides user iteractio i Scheme A expressio is read, evaluated, ad the result prited Iput: 9 Output: 9 Iput: (+ 3 4 Output: 7 Iput: (+ (* Output: 7 User ca load a program from a file with the load fuctio (load "my_scheme_program" Note: a file should use the.scm extesio COP4020 Fall

13 Workig with Data Structures A expressio operates o values ad compoud data structures built from atoms ad lists A value is either a atom or a compoud list Atoms are Numbers, e.g. 7 ad 3.14 Strigs, e.g. "abc" Boolea values #t (true ad #f (false Symbols, which are idetifiers escaped with a sigle quote, e.g. 'y The empty list ( Whe eterig a list as a literal value, escape it with a sigle quote Without the quote it is a fuctio ivocatio! For example, '(a b c is a list while (a b c is a fuctio applicatio Lists ca be ested ad may cotai ay value, e.g. '(1 (a b ''s'' COP4020 Fall

14 Checkig the Type of a Value The type of a value ca be checked with (boolea? x ; is x a Boolea? (char? x ; is x a character? (strig? x ; is x a strig? (symbol? x ; is x a symbol? (umber? x ; is x a umber? (list? x ; is x a list? (pair? x ; is x a o-empty list? (ull? x ; is x a empty list? Examples (list? '(2 #t (umber? ''abc'' #f Portability ote: o some systems false (#f is replaced with ( COP4020 Fall

15 Workig with Lists (car xs returs the head (first elemet of list xs (cdr xs (proouced "coulder" returs the tail of list xs (cos x xs jois a elemet x ad a list xs to costruct a ew list (list x 1 x 2 x geerates a list from its argumets Examples: (car '( (car '(2 2 (car '( Error (cdr '(2 3 (3 (car (cdr '( ; also abbreviated as (cadr '(2 3 4 (cdr (cdr '(2 3 4 (4 ; also abbreviated as (cddr '(2 3 4 (cdr '(2 ( (cos 2 '(3 (2 3 (cos 2 '(3 4 (2 3 4 (list (1 2 3 COP4020 Fall

16 The if Special Form Special forms resemble fuctios but have special evaluatio rules Evaluatio of argumets depeds o the special costruct The if special form returs the value of theexpr or elseexpr depedig o a coditio (if coditio theexpr elseexpr Examples (if #t (if #f 1 "a" "a" (if (strig? "s" ( (if (> 1 2 "yes" "o" "o" COP4020 Fall

17 The cod Special Form A more geeral if-the-else ca be writte usig the cod special form that takes a sequece of (coditio value pairs ad returs the first value x i for which coditio c i is true: (cod (c 1 x 1 (c 2 x 2 (else x Examples (cod (#f 1 (#t 2 (#t 3 2 (cod ((< 1 2 ''oe'' ((>= 1 2 ''two'' ''oe'' (cod ((< ((= (else 3 3 Note: else is used to retur a default value COP4020 Fall

18 Logical Expressios Relatios Numeric compariso operators <, <=, =, >, >= Boolea operators (ad x 1 x 2 x, (or x 1 x 2 x Other test operators (zero? x, (odd? x, (eve? x (eq? x 1 x 2 tests whether x 1 ad x 2 refer to the same object (eq? 'a 'a #t (eq? '(a b '(a b #f (equal? x 1 x 2 tests whether x 1 ad x 2 are structurally equivalet (equal? 'a 'a #t (equal? '(a b '(a b #t (member x xs returs the sublist of xs that starts with x, or returs ( (member 5 '(a b ( (member 5 '( (5 6 COP4020 Fall

19 Lambda Calculus: Fuctios = Lambda Abstractios A lambda abstractio is a ameless fuctio (a mappig specified with the lambda special form: (lambda args body where args is a list of formal argumets ad body is a expressio that returs the result of the fuctio evaluatio whe applied to actual argumets A lambda expressio is a uevaluated fuctio Examples: (lambda (x (+ x 1 (lambda (x (* x x (lambda (a b (sqrt (+ (* a a (* b b COP4020 Fall

20 Lambda Calculus: Ivocatio = Beta Reductio A lambda abstractio is applied to actual argumets usig the familiar list otatio (fuctio arg 1 arg 2... arg where fuctio is the ame of a fuctio or a lambda abstractio Beta reductio is the process of replacig formal argumets i the lambda abstractio s body with actuals Examples ( (lambda (x (* x x 3 (* ( (lambda (f a (f (f a (lambda (x (* x x 3 (f (f 3 where f = (lambda (x (* x x (f ( (lambda (x (* x x 3 where f = (lambda (x (* x x (f 9 where f = (lambda (x (* x x ( (lambda (x (* x x 9 (* COP4020 Fall

21 Defiig Global Names A global ame is defied with the defie special form (defie ame value Usually the values are fuctios (lambda abstractios Examples: (defie my-ame ''foo'' (defie determiers '(''a'' ''a'' ''the'' (defie sqr (lambda (x (* x x (defie twice (lambda (f a (f (f a (twice sqr 3 ((lambda (f a (f (f a (lambda (x (* x x 3 ((lambda (x (* x x ((lambda (x (* x x 3 ((lambda (x (* x x (* 3 3 (* COP4020 Fall

22 Usig Local Names The let special form (let-expressio provides a scope costruct for local ame-to-value bidigs (let ( (ame 1 x 1 (ame 2 x 2 (ame x expressio where ame 1, ame 2,, ame i expressio are substituted by x 1, x 2,, x Examples (let ( (plus + (two 2 (plus two two 4 (let ( (a 3 (b 4 (sqrt (+ (* a a (* b b 5 (let ( (sqr (lambda (x (* x x (sqrt (+ (sqr 3 (sqr 4 5 COP4020 Fall

23 Local Bidigs with Self Refereces A global ame ca simply refer to itself (for recursio (defie fac (lambda ( (if (zero? 1 (* (fac (- 1 A let-expressio caot refer to its ow defiitios Its defiitios are ot i scope, oly outer defiitios are visible Use the letrec special form for recursive local defiitios (letrec ( (ame 1 x 1 (ame 2 x 2 (ame x expr where ame i i expr refers to x i Examples (letrec ( (fac (lambda ( (if (zero? 1 (* (fac (- 1 (fac COP4020 Fall

24 I/O (display x prits value of x ad returs a uspecified value (display "Hello World!" Displays: "Hello World!" (display (+ 2 3 Displays: 5 (ewlie advaces to a ew lie (read returs a value from stadard iput (if (member (read '( "You guessed it!" "No luck" Eter: 5 Displays: You guessed it! COP4020 Fall

25 Blocks (begi x 1 x 2 x sequeces a series of expressios x i, evaluates them, ad returs the value of the last oe x Examples: (begi (display "Hello World!" (ewlie (let ( (x 1 (y (read (plus + (begi (display (plus x y (ewlie COP4020 Fall

26 Do-loops The do special form takes a list of triples ad a tuple with a termiatig coditio ad retur value, ad multiple expressios x i to be evaluated i the loop (do (triples (coditio ret-expr x 1 x 2 x Each triple cotais the ame of a iterator, its iitial value, ad the update value of the iterator Example (displays values 0 to 9 (do ( (i 0 (+ i 1 ( (>= i 10 "doe" (display i (ewlie COP4020 Fall

27 Higher-Order Fuctios A fuctio is a higher-order fuctio (also called a fuctioal form if It takes a fuctio as a argumet, or It returs a ewly costructed fuctio as a result For example, a fuctio that applies a fuctio to a argumet twice is a higher-order fuctio (defie twice (lambda (f a (f (f a Scheme has several built-i higher-order fuctios (apply f xs takes a fuctio f ad a list xs ad applies f to the elemets of the list as its argumets (apply '+ '(3 4 7 (apply (lambda (x (* x x '(3 (map f xs takes a fuctio f ad a list xs ad returs a list with the fuctio applied to each elemet of xs (map odd? '( (#t #f #t #f (map (lambda (x (* x x '( ( COP4020 Fall

28 No-Pure Costructs Assigmets are cosidered o-pure i fuctioal programmig because they ca chage the global state of the program ad possibly ifluece fuctio outcomes The value of a pure fuctio oly depeds o its argumets (set! ame x re-assigs x to local or global ame (defie a 0 (set! a 1 ; overwrite with 1 (let ( (a 0 (begi (set! a (+ a 1 ; icremet a by 1 (display a ; shows 1 (set-car! x xs overwrites the head of a list xs with x (set-cdr! xs ys overwrites the tail of a list xs with ys COP4020 Fall

29 Example 1 Recursive factorial: (defie fact (lambda ( (if (zero? 1 (* (fact (- 1 (fact 2 (if (zero? 2 1 (* 2 (fact (- 2 1 (* 2 (fact 1 (* 2 (if (zero? 1 1 (* 1 (fact (- 1 1 (* 2 (* 1 (fact 0 (* 2 (* 1 (if (zero? 0 1 (* 0 (fact (- 0 1 (* 2 (* COP4020 Fall

30 Example 2 Iterative factorial (defie iterfact (lambda ( (do ( (i 1 (+ i 1 ; i rus from 1 updated by 1 (f 1 (* f i ; f from 1, multiplied by i ( (> i f ; util i >, retur f ; loop body is omitted COP4020 Fall

31 Example 3 Sum the elemets of a list (defie sum (lambda (lst (if (ull? lst 0 (+ (car lst (sum (cdr lst (sum '(1 2 3 (+ 1 (sum (2 3 (+ 1 (+ 2 (sum (3 (+ 1 (+ 2 (+ 3 (sum ( (+ 1 (+ 2 (+ 3 0 COP4020 Fall

32 Example 4 Geerate a list of copies of x (defie fill (lambda ( x (if (= 0 ( (cos x (fill (- 1 x (fill 2 'a (cos a (fill 1 a (cos a (cos a (fill 0 a (cos a (cos a ( (a a COP4020 Fall

33 Example 5 Replace x with y i list xs (defie subst (lambda (x y xs (cod ((ull? xs ( ((eq? (car xs x (cos y (subst x y (cdr xs (else (cos (car xs (subst x y (cdr xs (subst 3 0 '( '( COP4020 Fall

34 Example 6 Higher-order reductios (defie reduce (lambda (op xs (if (ull? (cdr xs (car xs (op (car xs (reduce op (cdr xs (reduce ad '(#t #t #f (ad #t (ad #t #f #f (reduce * '(1 2 3 (* 1 (* (reduce + '(1 2 3 (+ 1 ( COP4020 Fall

35 Example 7 Higher-order filter operatio: keep elemets of a list for which a coditio is true (defie filter (lambda (op xs (cod ((ull? xs ( ((op (car xs (cos (car xs (filter op (cdr xs (else (filter op (cdr xs (filter odd? '( (1 3 5 (filter (lambda ( (<> 0 '( ( COP4020 Fall

36 Example 8 Biary tree isertio, where ( are leaves ad (val left right is a ode (defie isert (lambda ( T (cod ((ull? T (list ( ( ((= (car T T ((> (car T (list (car T (isert (cadr T (caddr T ((< (car T (list (car T (cadr T (isert (caddr T (isert 1 '(3 ( (4 ( ( (3 (1 ( ( (4 ( ( COP4020 Fall

37 Haskell A lazy fuctioal laguage with a static type system Lazy: evaluates expressios o demad, i.e. operads ad argumets are ot evaluated util used i the fuctio body Static type iferece: types are automatically iferred to verify expressios Polymorphic types Type variables, e.g. * i hd:: [*] -> * Higher-order fuctios Fuctios that take fuctios as argumets or retur fuctios Modular Compiled COP4020 Fall

38 Haskell Sytax Sytax of fuctio ivocatio: fuctioame arg 1 arg 2 arg 3 Note: parethesis oly eeded for ested calls, e.g. hd (tl xs Fuctio defiitio fuctioame arg 1 arg 2 arg 3 = expressio Fuctio defiitio with guards fuctioame arg 1 arg 2 arg 3 guard 1 = expressio 1 guard 2 = expressio 2 Lambda abstractio otatio: \ arg -> expressio COP4020 Fall

39 Haskell Sytax Lists ad primitive list operatios [e 1, e 2, e 3 ] e 1 : [e 2, e 3 ] evaluates to [e 1, e 2, e 3 ] hd [e 1, e 2, e 3 ] evaluates to e 1 tl [e 1, e 2, e 3 ] evaluates to [e 2, e 3 ] Commo list operatios legth [e 1, e 2, e 3 ] evaluates to 3 map f [e 1, e 2, e 3 ] evaluates to [f e 1, f e 2, f e 3 ] foldl! z [e 1, e 2, e 3 ] evaluates to ((z!e 1!e 2!e 3 foldr! z [e 1, e 2, e 3 ] evaluates to e 1!(e 2!(e 3!zfilter p [e 1, e 2, e 3 ] evaluates to list of e i whe p e i is true COP4020 Fall

40 Haskell by Example -- 1 usig if-the-else coditioal expressios factorial = if > 0 the * factorial (-1 else usig argumet patter matchig factorial 0 = 1 factorial = * factorial ( usig a guard factorial 0 = 1 factorial > 0 = * factorial (-1 -- type of the factorial fuctio factorial :: Iteger -> Iteger COP4020 Fall

41 Haskell by Example (cot d -- 1 list legth usig argumet patter legth [] = 0 legth (x:xs = 1 + legth xs -- 2 usig where legth [] = 0 legth (x:xs = 1 + rest where rest = legth xs -- 3 usig let legth [] = 0 legth (x:xs = { let rest = legth xs } i 1 + rest -- type of the legth fuctio (polymorphic legth :: [*] -> Iteger COP4020 Fall

42 Haskell by Example (cot d -- usig Curryig, which gives: ic x = add 1 x add a b = a + b ic = add higher-order, apply fuctio to each list elemet plus1 xs = map ic xs -- 2 usig Curryig plus1 = map ic COP4020 Fall

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

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

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

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

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

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

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 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

How do we evaluate algorithms?

How do we evaluate algorithms? F2 Readig referece: chapter 2 + slides Algorithm complexity Big O ad big Ω To calculate ruig time Aalysis of recursive Algorithms Next time: Litterature: slides mostly The first Algorithm desig methods:

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

. 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

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

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

implement language system

implement language system Outlie Priciples of programmig laguages Lecture 3 http://few.vu.l/~silvis/ppl/2007 Part I. Laguage systems Part II. Fuctioal programmig. First look at ML. Natalia Silvis-Cividjia e-mail: silvis@few.vu.l

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

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

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

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

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

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup Chapter 18 Vectors ad Arrays Bjare Stroustrup Vector revisited How are they implemeted? Poiters ad free store Destructors Iitializatio Copy ad move Arrays Array ad poiter problems Chagig size Templates

More information

CIS 121. Introduction to Trees

CIS 121. Introduction to Trees CIS 121 Itroductio to Trees 1 Tree ADT Tree defiitio q A tree is a set of odes which may be empty q If ot empty, the there is a distiguished ode r, called root ad zero or more o-empty subtrees T 1, T 2,

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

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

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

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

CSE 111 Bio: Program Design I Lecture 17: software development, list methods

CSE 111 Bio: Program Design I Lecture 17: software development, list methods CSE 111 Bio: Program Desig I Lecture 17: software developmet, list methods Robert H. Sloa(CS) & Rachel Poretsky(Bio) Uiversity of Illiois, Chicago October 19, 2017 NESTED LOOPS: REVIEW Geerate times table

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

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

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

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

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

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

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

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

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 3 More Flow of Cotrol Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 3.1 Usig Boolea Expressios 3.2 Multiway Braches 3.3 More about C++ Loop Statemets 3.4 Desigig Loops Copyright

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

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

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

Abstract Data Types (ADTs) Stacks. The Stack ADT ( 4.2) Stack Interface in Java

Abstract Data Types (ADTs) Stacks. The Stack ADT ( 4.2) Stack Interface in Java Abstract Data Types (ADTs) tacks A abstract data type (ADT) is a abstractio of a data structure A ADT specifies: Data stored Operatios o the data Error coditios associated with operatios Example: ADT modelig

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

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle:

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle: Recursio Recursio Jordi Cortadella Departmet of Computer Sciece Priciple: Reduce a complex problem ito a simpler istace of the same problem Recursio Itroductio to Programmig Dept. CS, UPC 2 Mathematical

More information

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs What are we goig to lear? CSC316-003 Data Structures Aalysis of Algorithms Computer Sciece North Carolia State Uiversity Need to say that some algorithms are better tha others Criteria for evaluatio Structure

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

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

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0 Polyomial Fuctios ad Models 1 Learig Objectives 1. Idetify polyomial fuctios ad their degree 2. Graph polyomial fuctios usig trasformatios 3. Idetify the real zeros of a polyomial fuctio ad their multiplicity

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

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

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming Lecture Notes 6 Itroductio to algorithm aalysis CSS 501 Data Structures ad Object-Orieted Programmig Readig for this lecture: Carrao, Chapter 10 To be covered i this lecture: Itroductio to algorithm aalysis

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

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

Priority Queues. Binary Heaps

Priority Queues. Binary Heaps Priority Queues Biary Heaps Priority Queues Priority: some property of a object that allows it to be prioritized with respect to other objects of the same type Mi Priority Queue: homogeeous collectio of

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

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

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

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

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control EE 459/500 HDL Based Digital Desig with Programmable Logic Lecture 13 Cotrol ad Sequecig: Hardwired ad Microprogrammed Cotrol Refereces: Chapter s 4,5 from textbook Chapter 7 of M.M. Mao ad C.R. Kime,

More information

5.3 Recursive definitions and structural induction

5.3 Recursive definitions and structural induction /8/05 5.3 Recursive defiitios ad structural iductio CSE03 Discrete Computatioal Structures Lecture 6 A recursively defied picture Recursive defiitios e sequece of powers of is give by a = for =0,,, Ca

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

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

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

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

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

BOOLEAN MATHEMATICS: GENERAL THEORY

BOOLEAN MATHEMATICS: GENERAL THEORY CHAPTER 3 BOOLEAN MATHEMATICS: GENERAL THEORY 3.1 ISOMORPHIC PROPERTIES The ame Boolea Arithmetic was chose because it was discovered that literal Boolea Algebra could have a isomorphic umerical aspect.

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

A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON

A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON Roberto Lopez ad Eugeio Oñate Iteratioal Ceter for Numerical Methods i Egieerig (CIMNE) Edificio C1, Gra Capitá s/, 08034 Barceloa, Spai ABSTRACT I this work

More information

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway. Bjare Stroustrup www.stroustrup.com/programmig Chapter 5 Errors Abstract Whe we program, we have to deal with errors. Our most basic aim is correctess, but we must deal with icomplete problem specificatios,

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

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity Time CSE 47: Algorithms ad Computatioal Readig assigmet Read Chapter of The ALGORITHM Desig Maual Aalysis & Sortig Autum 00 Paul Beame aalysis Problem size Worst-case complexity: max # steps algorithm

More information

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method A ew Morphological 3D Shape Decompositio: Grayscale Iterframe Iterpolatio Method D.. Vizireau Politehica Uiversity Bucharest, Romaia ae@comm.pub.ro R. M. Udrea Politehica Uiversity Bucharest, Romaia mihea@comm.pub.ro

More information

COP4020 Programming Assignment 1 - Spring 2011

COP4020 Programming Assignment 1 - Spring 2011 COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to

More information

n We have discussed classes in previous lectures n Here, we discuss design of classes n Library design considerations

n We have discussed classes in previous lectures n Here, we discuss design of classes n Library design considerations Chapter 14 Graph class desig Bjare Stroustrup Abstract We have discussed classes i previous lectures Here, we discuss desig of classes Library desig cosideratios Class hierarchies (object-orieted programmig)

More information

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8 The Implemetatio of Data Structures i Versio 5 of Ico* Ralph E. Gr is wo Id TR 85-8 April 1, 1985 Departmet of Computer Sciece The Uiversity of Arizoa Tucso. Arizoa 85721 This work was supported by the

More information

Chapter 3 Classification of FFT Processor Algorithms

Chapter 3 Classification of FFT Processor Algorithms Chapter Classificatio of FFT Processor Algorithms The computatioal complexity of the Discrete Fourier trasform (DFT) is very high. It requires () 2 complex multiplicatios ad () complex additios [5]. As

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

Analysis of Algorithms

Analysis of Algorithms Presetatio for use with the textbook, Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Aalysis of Algorithms Iput 2015 Goodrich ad Tamassia Algorithm Aalysis of Algorithms

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

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XIII March 2 nd, 2006 1 Roadmap Functional Languages Lambda Calculus Intro to Scheme Basics Functions Bindings Equality Testing Searching 2 1 Functional Languages

More information

Appendix D. Controller Implementation

Appendix D. Controller Implementation COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Appedix D Cotroller Implemetatio Cotroller Implemetatios Combiatioal logic (sigle-cycle); Fiite state machie (multi-cycle, pipelied);

More information

6.854J / J Advanced Algorithms Fall 2008

6.854J / J Advanced Algorithms Fall 2008 MIT OpeCourseWare http://ocw.mit.edu 6.854J / 18.415J Advaced Algorithms Fall 2008 For iformatio about citig these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 18.415/6.854 Advaced Algorithms

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information