ADT - Specification and Implementation of Abstract Data...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
cs784(Prasad) 1 Specification and Implementation of Abstract Data Types
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Spec v. Impl (Functional) Specs should describe behavioral aspects only Should ignore performance details A “suitable implementation” requires client specific issues and trade-offs. Even when you “can read” a suggested implementation from an Algebraic Spec, do not. Distribution of work among the various 22
Background image of page 2
cs784(Prasad) L34ADT 3 Data Abstraction Clients – Need to know WHAT functions/services a module provides, – Not (should not be) HOW they are carried out. – So, ignore details irrelevant to the overall behavior, for clarity. Implementors – May change the HOW (code), to improve performance, … – So, ensure that clients do not make unwarranted assumptions.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs784(Prasad) 4 Specification of Data Types Type : Values + Operations Specify Syntax Semantics Signature of Ops Meaning of Ops Model-based Algebraic Axioms Description in terms of Give axioms defining standard “primitive” data types the operations
Background image of page 4
cs784(Prasad) 5 Signatures of LISP S-expr Ops nil : S-expr cons : S-expr x S-expr S-expr car : S-expr S-expr cdr : S-expr S-expr null : S-expr boolean • for every atom a : a : l S-expr
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Signatures of LISP S-expr Ops • Signature tells us how to form complex terms from primitive operations. Legal nil null(cons(nil,nil)) cons(car(nil),nil) Illegal nil(cons) null(null) cons(nil) cs784(Prasad) L34ADT 6
Background image of page 6
cs784(Prasad) 7 Expectations of + : N x N N A Few Examples 1 + 2 = 3 zero + succ(succ(zero)) = succ(succ(zero)) x + 0 = x Relating to Other Operators 2 * (3 + 4) = 2 * 7 = 14 = 6 + 8 x * ( y + z) = x * y + x * z
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What to expect of S-Expr ? Examples null(nil) = true car(cons(nil,nil)) = nil null(cdr(cons(nil,cons(nil,nil)))) = false for all E,F in S-Expr car(cons(E,F)) = E null(cons(E,F)) = false cs784(Prasad) 8
Background image of page 8
Algebraic Specs of ADT • Operations on ADT – Constructors – Others • Axioms: True statements about the ADT • Algebraic Equational Axioms: LHS = RHS • LHS: Application of Operations • RHS: – similar to LHS, but – may also include if-expressions cs784(Prasad/pm) 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs784(Prasad) L34ADT 10 Algebraic Specs of ADTs Characteristics of an “Adequate” Specification – Completeness ( No “undefinedness” ) – Consistency/Soundness ( No conflicting definitions ) GOAL: Learn to write sound and complete algebraic specifications of ADTs
Background image of page 10
cs784(Prasad) L34ADT 11 Classification of Operations • Constructors – Generating values in the type • E.g., nil, cons, atoms a in ADT S-expr Every value ought to be “constructible” • Non-constructors – E.g., car, cdr in ADT S-expr • Observers – Extract a value outside the type • E.g., null in ADT S-expr • Constructors: As few as possible
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
• createStack: → Stack • push: Stack x element → Stack • pop: Stack → Stack, element • top: Stack → element • isEmpty: Stack → boolean • error an Element? cs784(pm)
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/02/2011 for the course CS 784 taught by Professor Tkprasad during the Spring '11 term at New York Institute of Technology-Westbury.

Page1 / 48

ADT - Specification and Implementation of Abstract Data...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online