Abstract Data Types! Documentation!

Similar documents
Abstract Data Types Documentation

Software Architecture. Abstract Data Types

Software Architecture. Abstract Data Types

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

Another common linear data structure similar to. new items enter at the back, or rear, of the queue. Queue is an ADT with following properties

Stack and Queue. Stack:

Linear Data Structures

CS 617 Object Oriented Systems Lecture 3 Object Abstractions, Encapsulation, Abstract Data Types 3:30-5:00pm Thu, Jan 10

CSE332: Data Abstractions Lecture 19: Mutual Exclusion and Locking

Assertions. Assertions - Example


Sequence Abstract Data Type

03/29/2004. A dispenser has three essential features: adding, removing, accessing. Dispensers

Stacks and Queues. CSE 373 Data Structures Lecture 6

Abstract Data Types (ADTs), Classes, and Objects

Computer Science 9608 (Notes) Chapter: 4.1 Computational thinking and problem-solving

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

ITI Introduction to Computing II

Test-Driven Development (TDD)

The Java Modeling Language (Part 2)

Midterm Exam (REGULAR SECTION)

D B M G D B M G 2. SQL language: other definitions. Transactions. Transactions. Introduction Transactions in SQL Properties of transactions

AN ECLECTIC COMPREHENSIVE APPROACH TO THE V&V OF SOFTWARE MODULES. Ali Mili, NJIT NII, Tokyo, Japan January 13, 2012

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

ABSTRACT DATA TYPES (ADTS) COMP1927 Computing 2 16x1 Sedgewick Chapter 4

CPSC 221: Algorithms and Data Structures Lecture #0: Introduction. Come up and say hello! Fibonacci. Fibonacci. Fibonacci. Fibonacci. (Welcome!

CSC148H Week 3. Sadia Sharmin. May 24, /20

Header Description: This use case describes how the ATM user withdraws cash from the ATM.

CSC148 Week 2. Larry Zhang

TIME: 3 HOURS MARKS: a. Develop a java program to sort an array of N numbers in ascending order. (40)

Problem with Scanning an Infix Expression

Assertions! How to write correct programs and know it! Harlan Mills! Gunnar Gotshalks! 08-1

JML Class Specifications The Java Modeling Language (Part 2) A Java Class

Lecture 12 ADTs and Stacks

Linked List. April 2, 2007 Programming and Data Structure 1

Adam Blank Lecture 1 Winter 2017 CSE 332. Data Abstractions

Stacks CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008

CS S-04 Stacks and Queues 1. An Abstract Data Type is a definition of a type based on the operations that can be performed on it.

ITI Introduction to Computing II

Data Structures and Algorithms

CS 302 ALGORITHMS AND DATA STRUCTURES

CS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.

CSCA48 Term Test 1 Seminar

Data Structure - Stack and Queue-

Programming By Contract: Designing for Correctness

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 4 Shared-Memory Concurrency & Mutual Exclusion

Assignment 2. CS 234 Fall 2018 Sandy Graham. Create()

Week 6. Data structures

III lecture: Contracts and Abstract Data Types. An obligation from last lecture... An obligation from last lecture... (2) January/February 2013

Lecture Data Structure Stack

csci 210: Data Structures Stacks and Queues

Last Class: Monitors. Real-world Examples

Data structure and algorithm in Python

1 P age DS & OOPS / UNIT II

Operating Systems. Sina Meraji U of T

COMP250: Stacks. Jérôme Waldispühl School of Computer Science McGill University. Based on slides from (Goodrich & Tamassia, 2004)

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

8. Fundamental Data Structures

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

CSCA48 Winter 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh, Nick Cheng University of Toronto Scarborough

Programmazione di sistemi multicore

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

Operating Systems. Synchronization

References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 10/14/2004 1

CSE 332: Data Structures & Parallelism Lecture 17: Shared-Memory Concurrency & Mutual Exclusion. Ruth Anderson Winter 2019

Ashish Gupta, Data JUET, Guna

From Data Structures to Abstract Data Types (ADTs)

LIFO : Last In First Out

Last Class: Synchronization Problems!

We need a formal algorithm, as visual inspection is not sufficient Many algorithms for detecting cycles in a directed graph are known o Below is a

SCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING. EKT224: ALGORITHM AND DATA STRUCTURES (Stack, Queue, Linked list)

Linked Structures. See Section 3.2 of the text.

Data Structures G5029

Software Architecture 4. July 2005

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Lecture No.04. Data Structures

Data Structure (CS301)

Queues. CITS2200 Data Structures and Algorithms. Topic 5

Datastructuren André Deutz

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010

Stacks. Common data structures - useful for organizing data for specific tasks Lists Stacks - an Abstract Data Type

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University

Learning Goals. CS221: Algorithms and Data Structures Lecture #3 Mind Your Priority Queues. Today s Outline. Back to Queues. Priority Queue ADT

Abstract Data Types. Definitions, Implementations, and Uses

Operating Systems. Operating Systems Sina Meraji U of T

Contracts. Dr. C. Constantinides. June 5, Department of Computer Science and Software Engineering Concordia University Montreal, Canada 1/71

Today s lecture. CS 314 fall 01 C++ 1, page 1

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

What is an algorithm?

PA3 Design Specification

List of Practical for Class XII Computer Science

Data Structures. BSc in Computer Science University of New York, Tirana. Assoc. Prof. Marenglen Biba 1-1

Motivation for Queues

IT 4043 Data Structures and Algorithms. Budditha Hettige Department of Computer Science

CMSC 132: Object-Oriented Programming II. Stack and Queue

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero).

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

Transcription:

! Abstract Data Types! Documentation! 13-1!

Documentation! Users are only interested in the properties of the ADT! Programmers and designers require all the information which a user needs AND all information pertaining to the design and implementation! Useful to think of the documentation as being an annotated definition of an abstract data type! 13-2!

Documentation Table of Contents! Cover page, table of contents and abstract! Document introduction!» Informal overview of the facilities provided. Help readers determine if this is what they need! Data type objects!» Description of all the objects include diagrams!» Split into! > Imported which predefined objects are used! > Exported for others to use! > Hidden used in the implementation! 13-3!

Operations TOC 2! Operations!» Give! > Signature! > Informal description! > pre- and post- conditions!» Use natural language, mathematics, diagrams whatever best gets the meaning across.!» Be simple, complete, clear, precise, concise as possible! 13-4!

Operations TOC 3! Example partial axiomatic description of bank accounts!» The operation signatures only no pre- post- given! new! : [] account! Create an account with a zero balance withdraw : account X amount Remove amount from account deposit : account X amount Add amount to account account! account! balance : account amount! What is the amount in the account? 13-5!

Operations TOC 4! Operation interaction!» Previous section describes operations in isolation!» Provide better understanding by showing properties when operations are used in combination!» Common descriptive method in use is axiomatic! > List of axioms or statements which must be true if the ADT is implemented and used correctly! 13-6!

Operations TOC 5! Axioms about the data type!» Axiom 1: New account has a balance of zero dollars! balance(new) = 0» Axiom 2: Cannot withdraw from a new account! withdraw(new, amt) = error» Axiom 3: Deposit amt and then withdraw amt with no intervening operations the balance does not change! balance( withdraw( deposit(acct, amt), amt) = balance(acct)» Axiom 4: Only withdraw if the balance is the amount to withdraw. The amount is deducted from the balance! balance(acct) < amt withdraw(acct, amt) = error balance(acct) amt balance(withdraw(acct, amt)) = balance(acct) amt 13-7!

TOC 6! How to use the ADT!» Tutorial guide on use. Dwell on nuances. Describe various examples! Dictionary!» Define new terminology or domain specific jargon that implementers or users may not know! Undesired Event Dictionary!» Description of possible errors which can occur!» Contains warnings!» How to recognize error situations!» How to recover from error situations!» What to do if recovery is impossible! 13-8!

TOC 7! ADT generation parameters!» Describe how instances and variations can be implemented from this generic data type! > How to change base types! > How to change amount of storage for a customer name!» Describe changes that can be made that will not violate assumptions and specifications. Design for a class of similar data types!» State what programming tools can be used to modify the implementation! 13-9!

TOC 8! Design issues!» What were the design choices and why were the actual choices chosen. Help guide future changes to keep in the spirit of the original! > Why was fixed memory allocation used instead of dynamic?! > Why were size limits imposed?! > Why was a particular data structure chosen?! 13-10!

TOC 9! Implementation notes!» Designer may have information of use to the implementer. Know properties that can improve implementation! List of assumptions those assumptions that!» Cannot be violated!» Not implicit in the context!» Global!» Note: cannot state all assumptions so state those that! > Are most important! > Most likely to cause problems if violated! > Are not easily detected as causing problems until a long time later! 13-11!

Normal use assumptions! TOC 10!» Information available from the ADT!» Information that must be supplied to the ADT!» Events reported by the ADT!» Tasks that can be performed by the ADT!» Operating states of the ADT and how they affect the Information obtained from and supplied to the ADT!» Failure states of the ADT and how they affect the information obtained from and supplied to the ADT! 13-12!

Incorrect use assumptions! TOC 11!» Associated with run time undesired events!» What may or may not happen if the production version has undesired event handling code removed to speed up the system! Program source text!» If the source test is small may be included with the description of the operations! Facilities index!» A quick look up reference of all programs, modules, operations, objects and terms defined! 13-13!

Minimal Documentation! Objects!» Types!!Diagrams where possible! Example stack!» Imported none!» Exported STACK [ G ]!» Hidden implementation! last! 7! capacity! 6! 5! 4! count! 3! 2! 1! Array up! 7! capacity! 6! 5! 4! 3! free! 2! 1! Array down! previous! previous! previous! previous! Linked list! 13-14!

Minimal Documentation 2! Operations example for a stack!» Signatures, pre & post conditions! > push : STACK [ G ] x G STACK [ G ]! require true ensure result = x ^ s & count = old count + 1 > pop : STACK [ G ] STACK [ G ]! require not empty ( s ) ensure result = s' & count = old count - 1 > top : STACK [ G ] G! require not empty ( s ) ensure result = s 1 13-15!

Minimal Documentation 3! Operations example for a stack cont'd! > empty : STACK [ G ] BOOLEAN! require true ensure result = ( count = 0 ) > new : [ ] STACK [ G ]! require true ensure result = STACK [ G ] count = 0» Note: often "require true" is not written but is assumed!» It is better to write it as then one can wonder if it was left out by accident! > "nothing" is often represented with a special symbol. e.g. nil, λ, ε, 13-16!

Minimal Documentation 4! Operations example for a stack cont'd!» Axioms! > x : G, s : STACK [ G ]! top ( push ( s, x ) ) = x! pop ( push ( s, x ) ) = s! empty ( new )! ~ empty ( push ( s, x ) )! is read as! "it is the case that"!» Alternately can use natural language! > forall x : G, s : STACK [ G } ::! top ( push ( s, x ) ) = x!and pop ( push ( s, x ) ) = s!and empty ( new )!and not empty ( push ( s, x ) )! 13-17!

ADT Invariants! Conditions that must be true after the execution of any method in the the class! The conditions that hold, at all times, among the objects in an instance of the ADT!» More on this when we discuss design by contract! 13-18!

Example Circular Queue! isempty length = 0 (last-1) mod Size = first! isfull length = Size - 1! not isfull length = (Size + first - last + 1) mod Size! n-3 n-2 n-1 0 1 2 last is the last! Item to remove! last first first is the first! Item to remove!... 13-19!

Empty Circular Queue! isempty length = 0 (last-1) mod Size = first! isfull length = Size - 1! not isfull length = (Size + first - last + 1) mod Size! n-3 n-2 n-1 first 0 last 1 2 length = (n + 1-2 + 1) mod n! = ( n + 0 ) mod n! = 0!... 13-20!

Empty Circular Queue 2! isempty length = 0 (last-1) mod Size = first! isfull length = Size - 1! not isfull length = (Size + first - last + 1) mod Size! n-3 n-2 first n-1 0 last 1 2 length = (n + (n-1) - 0 + 1) mod n! = ( 2n + 0 ) mod n! = 0!... 13-21!

Length 1 Circular Queue! isempty length = 0 (last-1) mod Size = first! isfull length = Size - 1! not isfull length = (Size + first - last + 1) mod Size! n-3 n-2 n-1 first 0 last 1 2 length = (n + 2-2 + 1) mod n! = ( n + 1 ) mod n! = 1!... 13-22!

Longer length Circular Queue!! length = (Size + first - last + 1) mod Size! length = (n + 3 - (n-3) + 1) mod n! = ( 7 ) mod n! = 7! n-3 n-2 n-1 0 1 2 last first... 13-23!