Data Structures and Algorithms for Engineers

Similar documents
CSI33 Data Structures

Data Structures and Algorithms for Engineers

Chapter 1: Programming Principles

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers

Chapter 1: Principles of Programming and Software Engineering

Contract Programming For C++0x

What is an algorithm?

Lecture 13 Hash Dictionaries

Motivation was to facilitate development of systems software, especially OS development.

Lecture 8 Data Structures

Data Structures and Algorithms for Engineers

Lecture Chapter 2 Software Development

Lecture 10 Linked Lists

Data Structures and Algorithms for Engineers

Object Oriented Programming

G Programming Languages - Fall 2012

However, in C we can group related variables together into something called a struct.

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

20. Inheritance and Polymorphism

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

Lethbridge/Laganière 2005 Chapter 9: Architecting and designing software 6

The Software Design Process. CSCE 315 Programming Studio, Fall 2017 Tanzir Ahmed

Instantiation of Template class

Chapter 1 Getting Started

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Motivation was to facilitate development of systems software, especially OS development.

CS 161 Computer Security

Princeton University Computer Science 217: Introduction to Programming Systems. Modules and Interfaces

Lecture Notes on Queues

Abstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples

Lecture 10 Notes Linked Lists

D Programming Language

CSCI387 Data Structure Fall. Aug. 21, 2012 Sung Hee Park Computer Science Virginia State University

ECE 2400 Computer Systems Programming Fall 2018 Topic 7: Concrete Data Types

Reasoning about programs

Section Notes - Week 1 (9/17)

CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L

Last time. Reasoning about programs. Coming up. Project Final Presentations. This Thursday, Nov 30: 4 th in-class exercise

3/7/2018. Sometimes, Knowing Which Thing is Enough. ECE 220: Computer Systems & Programming. Often Want to Group Data Together Conceptually

CE221 Programming in C++ Part 1 Introduction

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example

CS113: Lecture 9. Topics: Dynamic Allocation. Dynamic Data Structures

Lecture 2: C Programm

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Programming Style and Optimisations - An Overview


Exception Safety. CS 311 Data Structures and Algorithms Lecture Slides Wednesday, October 28, Glenn G. Chappell. continued

Chapter 19: Program Design. Chapter 19. Program Design. Copyright 2008 W. W. Norton & Company. All rights reserved.

Code Generation. Lecture 12

Lecture 7: Data Abstractions

Chapter 1: Key Concepts of Programming and Software Engineering

PROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development

Software Design Heuristics

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

CS121/IS223. Object Reference Variables. Dr Olly Gotel

EMBEDDED SYSTEMS PROGRAMMING OO Basics

V850 Calling Convention

CS64 Week 5 Lecture 1. Kyle Dewey

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm

Static Methods. Why use methods?

Lecture Notes on Contracts

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Goals of this Lecture

Lecture 10 Notes Linked Lists

Abstract data types &

Abstract Data Types & Object-Oriented Programming

CS 307: Software Engineering. Lecture 10: Software Design and Architecture

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

UNIT-4 (COMPILER DESIGN)

Review sheet for Final Exam (List of objectives for this course)

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Type Checking and Type Equality

Data Structures and Algorithms for Engineers

Lecture Notes on Queues

Compositional Cutpoint Verification

Absolute C++ Walter Savitch

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

QUIZ. What are 3 differences between C and C++ const variables?

Table 2 1. F90/95 Data Types and Pointer Attributes. Data Option. (Default Precision) Selected-Int-Kind

ECE 15B COMPUTER ORGANIZATION

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

Textbook. Topic 6: Functions. Motivation. What is a Function? What s a function? How can we use functions to write better software?

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

Array Based Lists. Collections

CS113: Lecture 9. Topics: Dynamic Allocation. Dynamic Data Structures

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

Lecture 3: C Programm

Introduction to Object- Oriented Programming

QUIZ Friends class Y;

C++ Alexander Baltatzis

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

CSE 333 Lecture 9 - intro to C++

Fundamentals of Programming Languages

Assertions. Assertions - Example

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

CS Lecture 19: Loop invariants

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

Transcription:

04-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University Africa

Lecture 7 Abstract Data Types (ADT) Abstract Data Types (ADT) Information hiding Types and typing Design goals Design practices Data Structures and Algorithms for Engineers 2 Carnegie Mellon University Africa

ADTs are an old concept Specify the complete set of values which a variable of this type may assume Specify completely the set of all possible operations which can be applied to values of this type Do so without reference to the underlying implementation (hence abstract) Information hiding (Dave Parnas) Data Structures and Algorithms for Engineers 3 Carnegie Mellon University Africa

It s worth noting that object-oriented programming gives us a way of combining (or encapsulating) both of these specifications in one logical definition Class definition (data members and methods, i.e. function members) Objects are instantiated classes Actually, object-oriented programming provides much more than this (e.g. inheritance and polymorphism) Data Structures and Algorithms for Engineers 4 Carnegie Mellon University Africa

Typing and Data Types Data types allow programmers to specify what kind of data a variable (or data structure) can store Typing is necessary so a computer knows how values in memory will be represented Native types typically include integer, floating point, character, string,... Native data types are built into languages ADTs are programmer-defined data types that are created from native types or other ADTs with the express purpose of hiding certain complexities. Data Structures and Algorithms for Engineers 5 Carnegie Mellon University Africa

An ADT Hides the way information is stored and the details of how the operations do what they do Exposes services that programmers can use to access, add, delete, manipulate, and transform data Are designed for general use, without a particular application or program flow in mind Data Structures and Algorithms for Engineers 6 Carnegie Mellon University Africa

Example Native types int MyInteger; char MyLetter; float ARealNumber; Programmer defined type #define SIZE 500 struct SomeStructType { /* stack is implemented as */ char items[size]; /* an array of items */ int num; /* number of items */ }; typedef struct SomeStructType MyType; /* struct type */ MyType stack; /* stack is a struct data structure */ Data Structures and Algorithms for Engineers 7 Carnegie Mellon University Africa

Example Native types int MyInteger; char MyLetter; float ARealNumber; Programmer defined type #define SIZE 500 struct SomeStructType { /* stack is implemented as */ char items[size]; /* an array of items */ int num; /* number of items */ }; typedef struct SomeStructType *MyType; /* pointer type */ MyType stack; /* variable is a pointer to a stack */ Data Structures and Algorithms for Engineers 8 Carnegie Mellon University Africa

ADT Design Goals The primary goal in designing an ADT is to hide complexity and implementation details Encapsulation is the principle of hiding the way that data is structured, the algorithms used, and providing access to the data and services by way of well-defined interfaces We can design systems as a collection of related and interacting capsules that hide various complexities within them Data Structures and Algorithms for Engineers 9 Carnegie Mellon University Africa

ADT Design Goals We must decide What data and operational details do we want to hide? What we have to expose so that (application) programmers can do what they need to do We must design The data organization (structure) & decide how we will allocate resources, store and access data The primitive data types or other ADTs that make up the ADT and the relationships between individual elements of the ADT we are creati The internal and exposed (external) operations are required to operate on the data Data Structures and Algorithms for Engineers 10 Carnegie Mellon University Africa

ADT Design Goals As in all software, in designing an ADT it must be correct: Potentially many applications will depend upon the ADT The data structure or algorithm should work correctly for all possible inputs that might be encountered Data Structures and Algorithms for Engineers 11 Carnegie Mellon University Africa

Data Structures and Algorithms for Engineers 16 Carnegie Mellon University Africa

Pre- and post-condition checks should be built into ADTs protects callers from doing bad things and helps prevent logical defects during execution checks can be derived from assertions made during algorithm analysis The goal in assertion checking is to check the input (preconditions) check for termination (normal and abnormal) check the result (post conditions) Data Structures and Algorithms for Engineers 17 Carnegie Mellon University Africa

Well designed and developed ADTs can Improve usability of services Hiding complexity, makes complex operations simple Take the underlying implementation understandable Facilitate reuse Ease maintenance and modifiability Poorly designed ADTs can totally undermine these characteristics Data Structures and Algorithms for Engineers 18 Carnegie Mellon University Africa

Design the ADT before you code Decide what the data and operations of the ADT will be before you write the code Consider modeling the ADT formally in terms of pre-conditions, postconditions, invariants... ADT operations should do only 1 thing Reuse your own operations never duplicate data or operations Think first. Code second. Data Structures and Algorithms for Engineers 19 Carnegie Mellon University Africa

Decide what you will hide Hide as much as possible from the user of the ADT Create the most intuitive interfaces possible for programmers Reduce inter-module dependencies to the greatest extent possible Data Structures and Algorithms for Engineers 20 Carnegie Mellon University Africa

Comment your code Code is written once and read many times Standardize to promote consistency Use coding/comment standards and naming conventions use them on internal and external operations and data Include headers explaining what the code does Traditionally called headers because they are comments at the beginning or head of the code body Provides an overview of what the code module does and something about its history Data Structures and Algorithms for Engineers 21 Carnegie Mellon University Africa

/******************************************************************************* * Source File: FooBar.c * Description: This file contains routines for implementing foobar functions. * Author: Gill Bates * Initial Production Date: 5/5/07 * Version: V1.2 * Calling Convention: FooBar( int FooInput, int BarOutput ); * Parameter List: * int FooInput integer foo like data * int BarOutput integer bar like data * Preconditions: FooInput must be greater than or equal to zero * Postconditions: BarOutput will be set to the relevant bar value based on FooInput * Functional Abstract:... * ******************************************** * Revision History * 12/25/07: Changed FooInput from float to int. Author: Jack Sommers * 07/04/08: Fixed problem with error message. Author: Jill Smith Data Structures and Algorithms for Engineers 22 Carnegie Mellon University Africa

Keep your code modules as simple as possible many small, simple operations are often easier to understand than a single complex operation Don t be cute and clever with code collapsing 5 lines of code into 1, may yield no advantage at all at execution time complex code is defect prone hard to understand what that 1 line of code does it is better to be sure and correct, than cute and clever and maybe wrong! Data Structures and Algorithms for Engineers 23 Carnegie Mellon University Africa

Design error handling from the very beginning Good error handling is a result of good correctness and behavioral analysis: error anticipation how the application will react to various types of errors, especially if aborts/halts are possible managing the consequences of errors Data Structures and Algorithms for Engineers 24 Carnegie Mellon University Africa