n Haskell n Syntax n Lazy evaluation n Static typing and type inference n Algebraic data types n Pattern matching n Type classes
|
|
- Conrad Randall
- 5 years ago
- Views:
Transcription
1 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 ad type iferece Algebraic data types Patter matchig Type classes Moads ad there is a lot more! Fall 18 CSCI 4430, A Milaova 1 Fall 18 CSCI 4430, A Milaova 2 Lecture Outlie Types Type systems Type checkig Type safety Type equivalece Types Read: Scott, Chapter 7 Types i C Fall 18 CSCI 4430, A Milaova 3 4 What Is a type? A set of values ad the valid operatios o those values Itegers: + - * / < <= = >= > Arrays: lookup(<array>,<idex>) assig(<array>,<idex>,<value>) iitialize(<array>), setbouds(<array>) User-defied types: Java iterfaces What Is the Role of Types? What is the role of types i programmig laguages? Sematic correctess Data abstractio Abstract Data Types (i Java) Documetatio (static types oly) 5 6 1
2 3 Views of Types Deotatioal (or set) poit of view: A type is simply a set of values. A value has a give type if it belogs to the set. E.g. it = { 1,2,... } char = { a, b,... } bool = { true, false } Abstractio-based poit of view: A type is a iterface cosistig of a set of operatios with well-defied meaig 7 3 Views of Types Costructive poit of view: Primitive/simple types: e.g., it, char, bool Composite/costructed types: Costructed by applyig type costructors poiter e.g., poiterto(it) array e.g., arrayof(char) or arrayof(char,20) or... record/struct e.g., record(age:it, ame:arrayof(char)) uio e.g. uio(it, poiterto(char)) CAN BE NESTED! poiterto(arrayof(poiterto(char))) For most of us, types are a mixture of these 3 views 8 What Is a Type System? A mechaism to defie types ad associate them with programmig laguage costructs Deduce types of costructs Deduce if a costruct is type correct or type icorrect What Is a Type System? Additioal rules for type equivalece, type compatibility Importat from pragmatic poit of view 9 10 What Is Type Checkig? The process of esurig that the program obeys the type rules of the laguage Type checkig ca be doe statically At compile-time, i.e., before executio Statically typed (or statically checked) laguage Type checkig ca be doe dyamically At rutime, i.e., durig executio Dyamically typed (or dyamically checked) laguage What Is Type Checkig? Statically typed (better term: statically checked) laguages Typically require type aotatios (e.g., A a, List<A> list) Typically have a complex type system, ad most of type checkig is performed statically (at compile-time) Ada, Pascal, Java, C++, Haskell, ML/OCaml A form of early bidig Dyamically typed (better term: dyamically checked) laguages. Also kow as Duck typed Typically require o type aotatios! All type checkig is performed dyamically (at rutime) Smalltalk, Lisp ad Scheme, Pytho, JavaScript 2
3 What Is Type Checkig? The process of esurig that the program obeys the type rules of the laguage Type safety Textbook defies term prohibited applicatio (also kow as forbidde error): ituitively, a prohibited applicatio is a applicatio of a operatio o values of the wrog type Type safety is the property that o operatio ever applies to values of the wrog type at rutime. I.e., o prohibited applicatio (forbidde error) ever occurs Laguage Desig Choices Desig choice: what is the set of forbidde errors? Obviously, we caot forbid all possible sematic errors Defie a set of forbidde errors Desig choice: Oce we ve chose the set of forbidde errors, how does the type system prevet them? Static checks oly? Dyamic checks oly? A combiatio of both? Furthermore, are we goig to absolutely disallow forbidde errors (be type safe), or are we goig to allow for programs to circumvet the system ad exhibit forbidde errors (i.e., be type usafe)? Forbidde Errors Example: idexig a array out of bouds a[i], a is of size Boud, i<0 or Boud i I C, C++, this is ot a forbidde error 0 i ad i<boud is ot checked (bouds are ot part of type) What are the tradeoffs here? I Pascal, this is a forbidde error. Preveted with static checks 0 i ad i<boud must be checked at compile time What are the tradeoffs here? I Java, this is a forbidde error. It is preveted with dyamic checks 0 i ad i<boud must be checked at rutime What are the tradeoffs here? 15 Type Safety Java vs C++: Java: Duck q; ; q.quack()class Duck has quack C++: Duck *q; ; q->quack()class Duck has quack Ca we write code that calls quack()o a object that is t a Duck? I Java? I C++? Java is said to be type safe while C++ is said to be type usafe 16 C++ Is Type Usafe What Is Type Checkig //#1 void* x = (void *) ew A; A virtual foo() B* q = (B*) x; //a safe dowcast? it case1 = q->foo()//what happes? B virtual foo() vritual foo(it) //#2 void* x = (void *) ew A; B* q = (B *) x; //a safe dowcast? it case2 = q->foo(66); //what happes? q->foo(66) is a prohibited applicatio (i.e., applicatio of a operatio o a value of the wrog type, i.e., forbidde error). Static type B* q promises the programmer that q will poit to a B object. However, laguage does ot hoor this promise type safe type usafe statically ot statically typed typed (i.e., dyamically typed) Assembly
4 What Is Type Checkig? Static typig vs. dyamic typig What are the advatages of static typig? Lecture Outlie Types Type systems Type checkig Type safety What are the advatages of dyamic typig? Type equivalece Types i C Type Equivalece ad Type Compatibility We ow move i the world of procedural vo Neuma laguages E.g., Fortra, Algol, Pascal ad C Value model Statically typed Type Equivalece ad Type Compatibility Questios e := expressio þ or ý Are e ad expressio of same type? a + b þ or ý Are a ad b of same type ad type supports +? foo(arg1, arg2,, argn) þ or ý Do the types of the argumets match the types of the formal parameters? Type Equivalece Two ways of defiig type equivalece Structural equivalece: based o shape Roughly, two types are the same if they cosists of the same compoets, put together i the same way Name equivalece: based o lexical occurrece of the type defiitio Strict ame equivalece Loose ame equivalece 23 Structural Equivalece A type ame is structurally equivalet to itself Two types are structurally equivalet if they are formed by applyig the same type costructor to structurally equivalet types (i.e., argumets are structurally equivalet) After type declaratio type = T or typedef T i C, the type ame is structurally equivalet to T Declaratio makes a alias of T. ad T are said to be aliased types Fall 18 CSCI 4430, A Milaova 24 4
5 Structural Equivalece Structural Equivalece Example, Pascal-like laguage: type S = array [0..99] of char type T = array [0..99] of char Example, C: typedef struct { it j, it k, it *ptr } cell; typedef struct { it, it m, it *p } elemet; Show by isomorphism of correspodig type trees Show the type trees of these costructed types Are these types structurally equivalet? struct cell struct elemet { char data; { char c; it a[3]; it a[5]; struct cell *ext; struct elemet *ptr; } } Equivalet types: are field ames part of the struct costructed type? are array bouds part of the array costructed type? Name Equivalece Name equivalece Roughly, based o lexical occurrece of type defiitio. A applicatio of a type costructor is a type defiitio. E.g., the red array[1..20] is oe type defiitio ad the blue array[1..20] is a differet type defiitio. type T = array [1..20] of it; x,y: array [1..20] of it; w,z: T; v: T; x ad y are of same type, w, z,v are of same type, but x ad w are of differet types! Questio Name equivalece w,z,v: array [1..20] of it; x,y: array [1..20] of it; Are x ad w of equivalet type accordig to ame equivalece? Aswer: x ad w are of distict types Name Equivalece A subtlety arises with aliased types (e.g., type = T, typedef it Age i C) Strict ame equivalece A laguage i which aliased types are cosidered distict, is said to have strict ame equivalece (e.g., it ad Age above would be distict types) Loose ame equivalece A laguage i which aliased types are cosidered equivalet, is said to have loose ame equivalece (e.g., it ad Age would be same) 29 Exercise type cell = // record/struct type type alik = poiter to cell type blik = alik p,q : poiter to cell r : alik s : blik t : poiter to cell u : alik Group p,q,r,s,t ito equiv. classes, accordig to structural equiv., strict ame equiv. ad loose ame equiv. 30 5
6 Example: Type Equivalece i C First, i the Algol family, field ames are part of the record/struct costructed type. E.g., the record types below are NOT eve structurally equivalet type A = record x,y : real ed; type B = record z,w : real ed; Type Equivalece i C Aoymous types are differetiated by iteral (compiler-geerated) type ames struct RecA typedef struct struct { char x; { char x; { char x; it y; it y; it y; } a; } RecB; } c; RecB b; Which variables are of equivalet type, accordig to the rules i C? Type Equivalece i C C uses structural equivalece for everythig, except uios ad structs, for which it uses loose ame equivalece struct A struct B { char x; { char x; it y; it y; } } typedef struct A C; typedef C *P; typedef struct B *Q; typedef struct A *R; typedef it Age; typedef it (*F) (it); Type Equivalece i C struct B { char x; it y; }; typedef struct B A; struct { A a; A *ext; } aa; struct { struct B a; struct B *ext; } bb; struct { struct B a; struct B *ext; } cc; A a; struct B b; a = b; aa = bb; bb = cc; typedef Age (*G) (Age); Which of the above assigmets pass the type checker? Questio Structural equivalece for record types is cosidered a bad idea. Ca you thik of a reaso why? Type Equivalece ad Type Compatibility Questios: e := expressio þ or ý Are e ad expressio of same type? e ad expressio may ot be of equivalet types, but they may be of compatible types. It may be possible to covert the type of expressio to the type of e Fall 18 CSCI 4430, A Milaova
7 Type Coversio Implicit coversio coercio Coversio doe implicitly by the compiler I C, mixed mode umerical operatios I e = expressio if e is a double ad expressio is a it, expressio is implicitly coerced i to a double double d,e; e = d + 2; //2 coerced to 2.0 Type Coversio Explicit coversio Programmer must ackowledge coversio I Pascal, roud ad truc perform explicit coversio roud(s) real to it by roudig truc(s) real to it by trucatig it to double, float to double How about float to it? No. May lose precisio ad thus, caot be coerced! I C, type castig performs explicit coversio freelist *s;... (char *)s; forces s to be cosidered as poitig to a char for the purposes of poiter arithmetic Lecture Outlie Types Type systems Type checkig Type safety Type equivalece Types i C Poiters: Poiters ad Arrays i C Poiters ad arrays are iteroperable: it ; it *a it b[10]; 1. a = b; 2. = a[3]; 3. = *(a+3); 4. = b[3]; 5. = *(b+3); Fall 18 CSCI 4430, A Milaova Type Declaratio i C What is the meaig of the followig declaratio i C? Draw the type trees. 1. it *a[] 2. it (*a)[] 3. it (*f)(it) 41 Type Declaratio i C typedef it (*PFB)(); // Type variable PFB: what type? struct parse_table { // Type struct parse_table: what type? char *ame; PFB fuc; }; it fuc1() {... } // Fuctio fuc1: what type? it fuc2() {... } struct parse_table table[] = { // Variable table: what type? {"ame1", &fuc1}, {"ame2", &fuc2} }; PFB fid_p_fuc(char *s) { // Fuctio fid_p_fuc: what type? for (i=0; i<um_fuc; i++) if (strcmp(table[i].ame,s)==0) retur table[i].fuc; retur NULL; } it mai(it argc,char *argv[]) {... } Fall 18 CSCI 4430, A Milaova 42 7
8 Type Declaratios i C Exercise Type tree for PFB: poiterto () it Type tree for type of fid_p_fuc: Eglish: a fuctio that takes a poiter to char as argumet, ad returs a poiter to a fuctio that takes void as argumet ad returs it. poiterto char poiterto () it struct _chuk { // Type struct_chuk: what type? char ame[10]; it id; }; struct obstack { // Type struct obstack: what type? struct _chuk *chuk; struct _chuk *(*chukfu)(); void (*freefu) (); }; void chuk_fu(struct obstack *h, void *f) { // Fuctio chuk_fu: what type? h->chukfu = (struct _chuk *(*)()) f; } void free_fu(struct obstack *h, void *f) { // Fuctio free_fu: what type? h->freefu = (void (*)()) f; } it mai() { struct obstack h; chuk_fu(&h,&xmalloc); free_fu(&h,&xfree);... } Fall 18 CSCI 4430, A Milaova 43 Fall 18 CSCI 4430, A Milaova 44 Type Declaratios i C Type tree for type of field chukfu: poiterto () poiterto struct _chuk: struct ame: array id: it char Fall 18 CSCI 4430, A Milaova 45 8
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 informationLast 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 informationLast 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 informationChapter 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 informationFrom 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 informationCOP4020 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 informationCS 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 informationimplement 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 informationtop() 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 informationCOP4020 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 informationSolution 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 informationOverview. 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 informationn 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 informationCOP4020 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 informationClasses 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 informationChapter 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 informationCOP4020 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 informationHash 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 informationBasic 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 informationOutline 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 informationAssignment 5; Due Friday, February 10
Assigmet 5; Due Friday, February 10 17.9b The set X is just two circles joied at a poit, ad the set X is a grid i the plae, without the iteriors of the small squares. The picture below shows that the iteriors
More informationCS 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 informationChapter 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 informationCOSC 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 informationExample: Shifter. Cascaded Combinational Shifter. Bluespec-2: Types. Asynchronous pipeline with FIFOs (regs with interlocks)
Bluespec-2: Types Arvid Computer Sciece & Artificial Itelligece Lab Massachusetts Istitute of Techology Eample: Shifter Goal: implemet: y = shift (,s) where y is shifted by s positios. Suppose s is a 3-bit
More informationChapter 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 informationCS : 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 informationLecture 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 informationPython 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 informationCMPT 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 informationn 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 informationRunning 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 informationData 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 informationCopyright 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 informationRunning 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 informationAnalysis 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 informationAbstract 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 informationPseudocode ( 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 informationBig-O Analysis. Asymptotics
Big-O Aalysis 1 Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is O(g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big-O expresses
More informationToday 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 informationGenerating Heap-bounded Programs in a Functional Setting
Geeratig Heap-bouded Programs i a Fuctioal Settig Walid Taha, Stepha Eller, ad Hogwei Xi 2 Rice Uiversity, Housto, TX, USA {taha,besa}@cs.rice.edu 2 Bosto Uiversity, Bosto, MA, USA hwxi@cs.bu.edu Abstract.
More informationSolutions 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 informationn 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 informationModule 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 informationPython 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 informationInductive 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 informationCSC 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 informationGoals of the Lecture UML Implementation Diagrams
Goals of the Lecture UML Implemetatio Diagrams Object-Orieted Aalysis ad Desig - Fall 1998 Preset UML Diagrams useful for implemetatio Provide examples Next Lecture Ð A variety of topics o mappig from
More informationcondition 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 informationLecture 6. Lecturer: Ronitt Rubinfeld Scribes: Chen Ziv, Eliav Buchnik, Ophir Arie, Jonathan Gradstein
068.670 Subliear Time Algorithms November, 0 Lecture 6 Lecturer: Roitt Rubifeld Scribes: Che Ziv, Eliav Buchik, Ophir Arie, Joatha Gradstei Lesso overview. Usig the oracle reductio framework for approximatig
More informationCS211 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 informationOnes 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 informationCIS 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 informationBig-O Analysis. Asymptotics
Big-O Aalysis 1 Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is O(g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big-O expresses
More informationMetaML and multi-stage programming with explicit annotations
Orego Health & Sciece Uiversity OHSU Digital Commos CSETech Jauary 1999 MetaML ad multi-stage programmig with explicit aotatios Walid Taha Tim Sheard Follow this ad additioal works at: http://digitalcommos.ohsu.edu/csetech
More informationRecursion. 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 information9.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 informationMatrix representation of a solution of a combinatorial problem of the group theory
Matrix represetatio of a solutio of a combiatorial problem of the group theory Krasimir Yordzhev, Lilyaa Totia Faculty of Mathematics ad Natural Scieces South-West Uiversity 66 Iva Mihailov Str, 2700 Blagoevgrad,
More informationCompiling and executing managed code
Compilig ad exectig maaged code Sorce Code Compilatio Lagage Compiler Microsoft Itermediate Lagage (MSIL) The first time each method is called Native Code Exectio JIT Compiler Commo Lagage Rtime C# .NET
More informationComputer Science Foundation Exam. August 12, Computer Science. Section 1A. No Calculators! KEY. Solutions and Grading Criteria.
Computer Sciece Foudatio Exam August, 005 Computer Sciece Sectio A No Calculators! Name: SSN: KEY Solutios ad Gradig Criteria Score: 50 I this sectio of the exam, there are four (4) problems. You must
More informationCHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs
CHAPTER IV: GRAPH THEORY Sectio : Itroductio to Graphs Sice this class is called Number-Theoretic ad Discrete Structures, it would be a crime to oly focus o umber theory regardless how woderful those topics
More informationAnalysis 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 informationLecture 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 informationMinimum Spanning Trees
Miimum Spaig Trees Miimum Spaig Trees Spaig subgraph Subgraph of a graph G cotaiig all the vertices of G Spaig tree Spaig subgraph that is itself a (free) tree Miimum spaig tree (MST) Spaig tree of a weighted
More informationWhat 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 informationExceptions. Your computer takes exception. The Exception Class. Causes of Exceptions
Your computer takes exceptio s s are errors i the logic of a program (ru-time errors). Examples: i thread mai java.io.filenotfoud: studet.txt (The system caot fid the file specified.) i thread mai java.lag.nullpoiter:
More informationAnnouncements TREES II. Comparing Data Structures. Binary Search Trees. Red-Black Trees. Red-Black Trees 3/13/18
//8 Aoucemets Prelim is Toight, brig your studet ID :PM EXAM OLH: etids startig aa to dh OLH: etids startig di to ji PHL: etids startig jj to ks (Plus studets who switched from the 7: exam) TREES II Lecture
More informationExamples 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 information1 Enterprise Modeler
1 Eterprise Modeler Itroductio I BaaERP, a Busiess Cotrol Model ad a Eterprise Structure Model for multi-site cofiguratios are itroduced. Eterprise Structure Model Busiess Cotrol Models Busiess Fuctio
More informationGoals 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 informationData diverse software fault tolerance techniques
Data diverse software fault tolerace techiques Complemets desig diversity by compesatig for desig diversity s s limitatios Ivolves obtaiig a related set of poits i the program data space, executig the
More informationDesigning a learning system
CS 75 Machie Learig Lecture Desigig a learig system Milos Hauskrecht milos@cs.pitt.edu 539 Seott Square, x-5 people.cs.pitt.edu/~milos/courses/cs75/ Admiistrivia No homework assigmet this week Please try
More informationifs considered Harmful
ifs cosidered Harmful Or; how to elimiate 90% of your bugs ad 99% of your techical debt i oe easy step. Jules May JulesMay.co.uk Codebase survey Bugs: all ~2.5 millio lies 5 years developmet 6-25 developers
More informationCounting the Number of Minimum Roman Dominating Functions of a Graph
Coutig the Number of Miimum Roma Domiatig Fuctios of a Graph SHI ZHENG ad KOH KHEE MENG, Natioal Uiversity of Sigapore We provide two algorithms coutig the umber of miimum Roma domiatig fuctios of a graph
More informationElementary 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 informationLecture 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 informationChapter 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Τεχνολογία Λογισμικού
ΕΘΝΙΚΟ ΜΕΤΣΟΒΙΟ ΠΟΛΥΤΕΧΝΕΙΟ Σχολή Ηλεκτρολόγων Μηχανικών και Μηχανικών Υπολογιστών Τεχνολογία Λογισμικού, 7ο/9ο εξάμηνο 2018-2019 Τεχνολογία Λογισμικού Ν.Παπασπύρου, Αν.Καθ. ΣΗΜΜΥ, ickie@softlab.tua,gr
More informationDesigning a learning system
CS 75 Itro to Machie Learig Lecture Desigig a learig system Milos Hauskrecht milos@pitt.edu 539 Seott Square, -5 people.cs.pitt.edu/~milos/courses/cs75/ Admiistrivia No homework assigmet this week Please
More informationBOOLEAN 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 informationStructuring 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 informationCS200: 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 informationCopyright 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 informationn 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 informationAbstract. 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 informationCS 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 informationCIS 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 information6.175: Constructive Computer Architecture. Oct 7,
6.175: Costructive Computer Architecture Tutorial 2 Advaced BSV Qua Nguye (Now uses the correct dates o PPT slides) T02-1 Admiistrivia Today is add date! Please test vlsifarm machies Remaiig labs schedule
More informationAnalysis 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 informationChapter 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 informationA 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 informationHigh-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 informationThe Semantics of an FP Language with Infinite Objects
The Sematics of a FP Laguage with Ifiite Objects TR88-022 April 1988 Teresa Ae Thomas The Uiversity of North Carolia at Chapel Hill Departmet of Computer Sciece CB#3175, Sitterso Hall Chapel Hill, NC 27599-3175
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationOverview. Common tasks. Observation. Chapter 20 The STL (containers, iterators, and algorithms) 8/13/18. Bjarne Stroustrup
Overview Chapter 20 The STL (cotaiers, iterators, ad algorithms) Bjare Stroustrup www.stroustrup.com/programmig Commo tasks ad ideals Geeric programmig Cotaiers, algorithms, ad iterators The simplest algorithm:
More information5.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 informationCIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)
CIS 11 Data Structures ad Algorithms with Java Fall 017 Big-Oh Notatio Tuesday, September 5 (Make-up Friday, September 8) Learig Goals Review Big-Oh ad lear big/small omega/theta otatios Practice solvig
More informationA Type System for Safe Memory Management and its Proof of Correctness
A Type System for Safe Memory Maagemet ad its Proof of Correctess Mauel Moteegro Ricardo Peña Clara Segura Dpto. de Sistemas Iformáticos y Computació Uiv. Complutese de Madrid C/ Prof. José García Satesmases
More informationTopics. Instance object. Instance object. Fundamentals of OT. Object notation. How do objects collaborate? Pearson Education 2007 Appendix (RASD 3/e)
Appedix (RASD 3/e) MACIASZEK, L.A. (2007): Requiremets Aalysis ad System Desig, 3 rd ed. Addiso Wesley, Harlow Eglad ISBN 978-0-321-44036-5 Appedix Fudametals of Object Techology Pearso Educatio Limited
More informationData Types (cont.) Administrative Issues. Academic Dishonesty. How do we detect plagiarism? Strongly Typed Languages. Type System
CSE 3302 Programming Languages Data Types (cont.) Chengkai Li Fall 2007 1 Administrative Issues Midterm Exam (in class) Tuesday, Oct. 16 th Schedule Change HW1 HW1 part1 & HW1 part2 Due at the same time,
More information