ࡱ> =]  !"#$%&'()*+,-./0123456789:;<[@ABCDEFGHIJKLMNOPQRSTUVWXYZ\RdO) n׼>@PowerPoint Document(uSummaryInformation(?6DocumentSummaryInformation86(   "6"Wagner@cs.ucr.eduN:http://www.cs.ucr.edu/~wagnerH4http://www.cs.ucr.edu/cs12/ 0DTimes New Romanla 'K DArialNew Romanla 'K  DWingdingsRomanla 'K 0DZapf Dingbatsnla 'K @DTekton Plus RegularSC'K PDBillsDingbatsgularSC'K  ` .  @n?" dd@  @@`` xnT       c $ n3f3@8d >$ʚ;+4ʚ;g4QdQd@t@ppp@ <4!d!d-gX<4dddd-gXg4`d`d4@@8p@ pp>___PPT9 h___PPT2001D<4X?-"2003 W L Truppel bCS 14: Intro. Data Structures & Algs. " Lecture 2O =)%Intro to Data Structures & AlgorithmsWagner Truppel Lecturer, Dept. of Computer Science & Engineering UC Riverside wagner@cs.ucr.edu http://www.cs.ucr.edu/~wagner http://www.cs.ucr.edu/cs14zO  O`a~Today s TopicsReview of abstraction: Interface Implementation Some notation to describe interfaces Syntax and Semantics Abstract Data Types (ADTs) ADT example: Counter Summary<ZZrZrNCInterface x Implementation:Consider an int variable int is a data type It could be that the computer you re using stores int s in 1 s complement or 2 s complement format When you use it, you don t care how it s really implemented inside the computer All you care is that the following operations are defined for that particular data type: +, -, *, /, <, >, <=, >=, ==, !=, ++, -- A data type like that is called an Abstract Data Type or ADT 8Z) uZ=Z  2#> @:aFInterface x ImplementationA data type like that is called an Abstract Data Type or ADT Well& not quite: an interface alone does not define an ADT (more on this later) Still& an interface is part of the definition of an ADT How do you describe an interface? We need some notation& XZ#e]bGNotationSay we want to describe what the operation + does to integers + takes two ints as its operands it s a binary operation + produces an int as a result Same with  But there s another kind of  operation: It takes one int and changes its sign a unary operation In general, then, we need to specify the number of operands and their types, as well as the type of the result >ZYZ5Z:ZoZZ+        n  >J7NcHNotation+ : int X int int (binary +)  : int X int int (binary  )  : int int (unary  ) Don t panic ! This is just a convenient notation. No deep concepts involved here& Now, is this enough though ? The function int f(int a, int b) { return a; } satisfies the definition for + but it does not correspond to addition !nZ}ZmZ#%}#*ZdISyntax and SemanticsEThe interface (ie, set of operations) defines the syntax of the ADT We also need to define its semantics Say again ? Take English as an example: The computer went out for lunch. It satisfies the grammatical rules of English (its syntax) It makes no sense, though It violates the semantics of English Semantics defines meaningZZZ2' (T,    5eJ Quick Summary Thus, we have: ADT Interface (operations syntax) Axioms (expected semantics) Implementation An ADT is made of an interface and its semantics The semantics is like a contract: It specifies what is expected from the operations defined by the interface Important for testingZZ;ZZSZaZ;SafKBack to + and  Interface (syntax): + : int X int int (binary +)  : int X int int (binary  )  : int int (unary  ) Semantics (contract): + does indeed add its operands Binary  does indeed subtract its operands from one another in a specified order Unary  does indeed change its operand s sign Interface + semantics = ADT:ZoZZZZ #%%O'gLAnother example: CounterWe want to define an ADT called Counter What is it good for? What should its interface (syntax) be? get: to access the counter s current value inc: to increment the counter s current value Hmm& ok, but just b/c we called them that, it doesn t mean that they do what we expect them to do How do we describe the semantics of the Counter interface? We need more notation: axioms~dZYZZd(+hMCounter adt Counter //  filename uses Integer // other adt s used defines Counter // name of type defined operations get: Counter int //  observer inc: Counter Counter //  modifier new: Counter //  constructor preconditions // none for this adt axioms //  contract get( new() ) = 0 // new starts at 0 get( inc(c) ) = get(c) + 1 // inc s by 1 v}Z& .N?=)2iNCounter Ok, now what? Now we have an ADT (an interface) for a data type which counts up from zero in steps of 1 Nowhere we said anything about how to implement this ADT/PsxHH@Rg(HH(dh   ` www3ff` 3fff` ___>?" dF@,?n<d@uA @ " d`  n?" dd@   @@``PR   @ ` `P0p>> -"2003 W L Truppel bCS 14: Intro. Data Structures & Algs. " Lecture 2 j( = 2  Ne0?"! :    Nd0gֳgֳ ?"P  T Click to edit Master title style! !<  H f0gֳgֳ ?"  RClick to edit Master text styles Second level Third level Fourth level Fifth level!     S  Nf0gֳgֳ ?"`p  Z*    N`h0gֳgֳ ?"`   n*2    Ni0gֳgֳ ?"`@  \*   N  6n޽h? ? www3ff $Blank PresentationM  -"2003 W L Truppel bCS 14: Intro. Data Structures & Algs. " Lecture 2 =5  ( |  B  N1?"442  Nj0?"! :    Ni0gֳgֳ ?"` D T Click to edit Master title style! !  Hk0gֳgֳ ?"P  D W#Click to edit Master subtitle style$ $  Nl0gֳgֳ ?"`p D Z*    N`n0gֳgֳ ?"`@ D \*     Ngֳgֳ ?"`  D n*2  N  6n޽h? ?  www3ff  P<f(  < < 00] "P   ה R*   < 0P^ "   ה T*  r < c $ ?"  ה$ < 0p_ " @ ה RClick to edit Master text styles Second level Third level Fourth level Fifth level!     S < 6_ "`P  ה R*   < 6Pa "`  ה T*  H < 0޽h ? ̙33h 80D( @ $  D D 0'& "P   ה V CS 14 ADTs   D 0 %& "   ה T*   D 6$& "`P  ה V CS 14 ADTs   D 6 O "`  ה T*  H D 0޽h ? ̙33  d\0 (  P   c $ "P D   c $ "P  D    <лD :  B  s *޽h ? 3ff   `@(    S e"P  D   S f"  D B  s *޽h ? 33̙ff   pPL(  P P c $0f"`  D  P c $pe" D B P s *޽h ? 33̙ff  N :2( 00//   c $`r "`  D    c $r "$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  a :2(    c $@w "`  D    c $@t "$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  b :2(    c $ y "`  D    c $x "$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  c :2( 00//   c $F"`  D    c $ F"$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  d :2(    c $,"`  D    c $0,"0$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  e :2( 00//   c $P,"`  D    c $,"0$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  f :2( 00//   c $,"`  D    c $0,"0$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  g :2( |   c $L"`  D    c $N"0$ DPH___PPT2001$ΐ B  s *޽h ? 33̙ff  h :2( 00//   c $,"`  D    c $,"0$ DPH___PPT2001$ΐ B  s *޽h ? 33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^~y)Φnnnnnnnnف~G *f Ψnnnnnnnnnnnnnnn nnnnnnnnn~  *=  Ωnn nnnnnnnnnnn nnnnnnnnnnnnnnnnف~ * ͫtnn nnnnnnnnnnnnnnnnnnnn7~+ͭnnn(~+ͮnn~W+tͯn~,,Qͱn~,1Ͳon~؄,߄̴xn~-̴n~-̶n~b-~̷n~?.b̸n~.D̹n~.˺pn~ԅ.܅˻znv~/˼nnnnnnnnnnnn~/˽nnnnnnnnnnnnnnnnnnnnn~| / ˾nnnnnnnnnnnnn nnnnnnnnnnnnn~_/}˿nnnnnnnnnnnnnnnn+~B0fnn(~'0Pnn~0=n~0on~0wn~͆0׆~n~1Ćn~1n~1n~1n~s1n~c1n~S1tn~F2kn~<2cn~32[n݁~ )22222222 S nnnnnnnnnnnnnnnnnn$~ 222222222222Lnnnnnnnnnnnnnnnnnnnnnnnnnnnn~ 22222 D nnnnnnnnnnnnnnnnnnnn7~222?nn~ 2=ņn~ 2:Ɔn~27Ɇn~25Ɇn~2ˆnmsTodays TopicsInterface x ImplementationInterface x Implementation Notation NotationSyntax and SemanticsQuick SummaryBack to + and Another example: CounterCounterCounter  Fonts UsedDesign Template Slide Titles  8@ _PID_HLINKS'AHmailto:Wagner@cs.ucr.eduhttp://www.cs.ucr.edu/~wagnerhttp://www.cs.ucr.edu/cs12&_uCTWagner TruppelCurrent User.