Concrete Abstractions

Similar documents
An Introduction to Programming with IDL

CLASSIC DATA STRUCTURES IN JAVA

This page intentionally left blank

DATA ABSTRACTION AND PROBLEM SOLVING WITH JAVA

Object-Oriented Programming and Data Structures

DESIGN AND VALIDATION OF COMPUTER PROTOCOLS

Understanding and Writing Compilers

An Introduction to Object-Oriented Programming

Data Structures in C++ Using the Standard Template Library

Workbook for C++ THIRD EDITION. Yedidyah Langsam, Ph.D. Brooklyn College of the City University of New York. Custom Publishing

Real-Time Systems and Programming Languages

Programming with POSIX Threads

LATEX. Leslie Lamport. Digital Equipment Corporation. Illustrations by Duane Bibby. v ADDISON-WESLEY

EMBEDDED SYSTEMS: Jonathan W. Valvano INTRODUCTION TO THE MSP432 MICROCONTROLLER. Volume 1 First Edition June 2015

Kentrox DataSMART DSU/CSU Management Module Guide

INFORMATION RETRIEVAL SYSTEMS: Theory and Implementation

Data Structures and Abstractions with Java

Graphics Programming in c++

Application Programming

SDH/SONET Explained in Functional Models

Digital Signal Processing System Design: LabVIEW-Based Hybrid Programming Nasser Kehtarnavaz

Next Generation Networks Perspectives and Potentials. Dr Jingming Li Salina LiSalina Consulting, Switzerland Pascal Salina Swisscom SA, Switzerland

PROBLEM SOLVING USING JAVA WITH DATA STRUCTURES. A Multimedia Approach. Mark Guzdial and Barbara Ericson PEARSON. College of Computing

Excel for Chemists. Second Edition

Digital Image Processing

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez

Essential Series. Springer-Verlag London Ltd.

Programming in Python 3

DATABASE SYSTEM CONCEPTS

Programming Clojure. Extracted from: Second Edition. The Pragmatic Bookshelf

Security for Microsoft Windows System Administrators

The Unified Modeling Language User Guide

C++ Primer, Fifth Edition

MASTERING COBOL PROGRAMMING

Quality Code. Software Testing Principles, Practices, and Patterns. Stephen Vance. AAddison-Wesley

HASHING IN COMPUTER SCIENCE FIFTY YEARS OF SLICING AND DICING

NetIQ User Conferentie NetIQ Update. Travis Greene Chief Service Management Strategist

Programming. In Ada JOHN BARNES TT ADDISON-WESLEY

User Guide. Informatica PowerCenter Connect for MSMQ. (Version 8.1.1)


Win32 Network Programming

QoS OVER HETEROGENEOUS NETWORKS

A Structured Programming Approach to Data

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

Prelude to Programming

[CHAPTER] 1 INTRODUCTION 1

Agile Database Techniques Effective Strategies for the Agile Software Developer. Scott W. Ambler

Guide to RISC Processors

Information Modeling and Relational Databases

DATA STRUCTURES AND PROBLEM SOLVING USING JAVA

UML for SOC Design GRANT MARTIN WOLFGANG MÜLLER. Edited by. Tensilica Inc., Santa Clara, CA, USA. and. University of Paderborn, Germany

Digital Electronics A Practical Approach with VHDL William Kleitz Ninth Edition

Program and Electronic Projects for the SSC, Electron and Spectrum Computers

Networked Graphics 01_P374423_PRELIMS.indd i 10/27/2009 6:57:42 AM

The SQL Guide to Pervasive PSQL. Rick F. van der Lans

ARCHITECTURE AND CAD FOR DEEP-SUBMICRON FPGAs

The VAXNMS Station supports the Cray operating system COS, version 1.13 or higher, and the Cray operating system UNICOS, release 2.0 or higher.

Microprocessor Theory

Journal Citation Reports on the Web v.2.0 sem-jcr

Engineering Problem Solving with C++

PYTHON. p ykos vtawynivis. Second eciitiovl. CO Ve, WESLEY J. CHUN

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

SymbolicC++: An Introduction to Computer Algebra using Object-Oriented Programming

Replicator Replicating Managed Metadata

FUZZY LOGIC WITH ENGINEERING APPLICATIONS

Open-Source Robotics and Process Control Cookbook

MARKETING ALLIANCE MEDIA KIT 2016/17

Pearson New International Edition. The 8051 Microcontroller and Embedded Systems Mazidi Mazidi McKinlay Second Edition

Replicator Replicating Managed Metadata

Programming with Turing and Object Oriented Turing

Jinkun Liu Xinhua Wang. Advanced Sliding Mode Control for Mechanical Systems. Design, Analysis and MATLAB Simulation

Computer Architecture

HTML5 MOBILE WEBSITES

Scheduling in Distributed Computing Systems Analysis, Design & Models

COMPUTER AND ROBOT VISION

CLEANROOMS. Facilities and Practices. M. Kozicki. Arizona State University. with S. Hoenig. University of Arizona. and. P.

High-Performance Parallel Database Processing and Grid Databases

Network Performance Analysis

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu. .~Addison-Wesley

Acknowledgments The author and editors wish to thank the following instructors for their technical and academic contributions:

Big Java Late Objects

Objects First with Java

Odin. SMB Cloud InsightsTM GLOBAL

Installing PI AF with SQL Server 2012 AlwaysOn Availability Group Feature. Version 1.0

Database Concepts. David M. Kroenke UNIVERSITATSBIBLIOTHEK HANNOVER

Rendering with mental ray and 3ds Max

Unlocking the Power of OPNET Modeler

DBArtisan New Features Guide

Revolutionary Industrial PC for IoT Era With innovative i-modules For flexible expansion

A Document Preparation System. User's Guide and Reference Manual. Leslie Lamport

Mathematica for Scientists and Engineers

Systems:;-'./'--'.; r. Ramez Elmasri Department of Computer Science and Engineering The University of Texas at Arlington

Hello! Python. Anthony Briggs MANNING SHELTER ISLAND

George Grätzer. Practical L A TEX

Structured Parallel Programming Patterns for Efficient Computation

Pearson Inform 5.1. User Guide. Adding, Editing and Deleting Folders. Date: 1/26/2010. Copyright 2009 Pearson Education, Inc. or its affiliate(s).

GLOBAL EDITION. Assembly Language. for x86 Processors SEVENTH EDITION. Kip R. Irvine

A Structured Programming Approach to Data

Domain-Specific. Languages. Martin Fowler. AAddison-Wesley. Sydney Tokyo. With Rebecca Parsons

Transcription:

Concrete Abstractions

Concrete Abstractions An Introduction to Computer Science Using Scheme Max Hailperin Gustavus Adolphus College Barbara Kaiser Gustavus Adolphus College Karl Knight Gustavus Adolphus College An Imprint of Brooks/Cole Publishing Company An International Thomson Publishing Company Pacific Grove Albany Belmont Bonn Boston Cincinnati Detroit Johannesburg London Madrid Melbourne Mexico City New York Paris Singapore Tokyo Toronto Washington

Sponsoring Editor: Suzanne Jeans Marketing Team: Nathan Wilbur, Michele Mootz Editorial Assistant: Kathryn Schooling Production Manager: Marlene Thom Manuscript Editor: Linda Thompson Interior Design: Merry Obrecht Sawdey Cover Design: Vernon T. Boes Cover Photo: Craig Cowan. Courtesy of Couturier Gallery, Los Angeles, CA Project Management and Typesetting: Integre Technical Publishing Co., Inc. Printing and Binding: Webcom, Ltd. COPYRIGHT 1999 by Brooks/Cole Publishing Company A division of International Thomson Publishing Inc. The ITP logo is a registered trademark used herein under license. Java TM is a trademark of Sun Microsystems, Inc. All other products used herein are used for identification purposes only, and may be trademarks or registered trademarks of their respective owners. For more information, contact: BROOKS/COLE PUBLISHING COMPANY 511 Forest Lodge Road Pacific Grove, CA 93950 USA International Thomson Publishing Europe Berkshire House 168 173 High Holborn London WC1V 7AA England Thomas Nelson Australia 102 Dodds Street South Melbourne, 3205 Victoria, Australia Nelson Canada 1120 Birchmount Road Scarborough, Ontario Canada M1K 5G4 International Thomson Editores Seneca 53 Col. Polanco 11560 México, D.F., México International Thomson Publishing GmbH Königswinterer Strasse 418 53227 Bonn Germany International Thomson Publishing Asia 221 Henderson Road #05 10 Henderson Building Singapore 0315 International Thomson Publishing Japan Hirakawacho Kyowa Building, 3F 2-2-1 Hirakawacho Chiyoda-ku, Tokyo 102 Japan All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transcribed, in any form or by any means electronic, mechanical, photocopying, recording, or otherwise without the prior written permission of the publisher, Brooks/Cole Publishing Company, Pacific Grove, California 93950. Printed in Canada 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging in Publication Data Hailperin, Max. Concrete abstractions : an introduction to computer science using Scheme / Max Hailperin, Barbara Kaiser, Karl Knight. p. cm. ISBN 0-534-95211-9 (alk. paper) 1. Computer science. 2. Abstract data types (Computer science) I. Kaiser, Barbara (Barbara K.). II. Knight, Karl (Karl W.). III. Title. QA76.H296 1997 005.13 3 dc21 98-34080 CIP THIS BOOK IS PRINTED ON ACID-FREE RECYCLED PAP ER

Contents Preface ix PART I Procedural Abstraction CHAPTER 1 Computer Science and Programming 3 1.1 What s It All About? / 3 Sidebar: Responsible Computer Use / 5 1.2 Programming in Scheme / 5 1.3 An Application: Quilting / 15 CHAPTER 2 Recursion and Induction 22 2.1 Recursion / 22 Sidebar: Exponents / 28 2.2 Induction / 28 2.3 Further Examples / 34 2.4 An Application: Custom-Sized Quilts / 40 CHAPTER 3 Iteration and Invariants 48 3.1 Iteration / 48 3.2 Using Invariants / 54 3.3 Perfect Numbers, Internal Definitions, and Let / 58 3.4 Iterative Improvement: Approximating the Golden Ratio / 61 3.5 An Application: The Josephus Problem / 65 v

vi Out of print; full text available for free at http://www.gustavus.edu/+max/concrete-abstractions.html Contents CHAPTER 4 Orders of Growth and Tree Recursion 75 4.1 Orders of Growth / 75 Sidebar: Selection Sort / 77 Sidebar: Merge Sort / 78 Sidebar: Merging / 79 Sidebar: Logarithms / 82 4.2 Tree Recursion and Digital Signatures / 83 Sidebar: Modular Arithmetic / 87 4.3 An Application: Fractal Curves / 95 CHAPTER 5 Higher-Order Procedures 109 5.1 Procedural Parameters / 109 5.2 Uncomputability / 113 Sidebar: Alan Turing / 116 5.3 Procedures That Make Procedures / 118 5.4 An Application: Verifying ID Numbers / 120 PART II Data Abstraction CHAPTER 6 Compound Data and Data Abstraction 133 6.1 Introduction / 133 6.2 Nim / 135 6.3 Representations and Implementations / 143 Sidebar: Nim Program / 144 Sidebar: Game State ADT Implementation / 152 6.4 Three-Pile Nim / 153 6.5 An Application: Adding Strategies to Nim / 156 Sidebar: Type Checking / 157 CHAPTER 7 Lists 167 7.1 The Definition of a List / 167 7.2 Constructing Lists / 169 7.3 Basic List Processing Techniques / 172 7.4 List Processing and Iteration / 179 7.5 Tree Recursion and Lists / 182

Contents vii 7.6 An Application: A Movie Query System / 187 Sidebar: Is There More to Intelligence Than the Appearance of Intelligence? / 202 CHAPTER 8 Trees 212 8.1 Binary Search Trees / 212 8.2 Efficiency Issues with Binary Search Trees / 220 Sidebar: Privacy Issues / 225 8.3 Expression Trees / 226 8.4 An Application: Automated Phone Books / 229 CHAPTER 9 Generic Operations 243 9.1 Introduction / 243 9.2 Multiple Representations / 244 9.3 Exploiting Commonality / 253 9.4 An Application: Computer Graphics / 262 CHAPTER 10 Implementing Programming Languages 278 10.1 Introduction / 278 10.2 Syntax / 279 Sidebar: The Expressiveness of EBNF / 285 10.3 Micro-Scheme / 289 10.4 Global Definitions: Mini-Scheme / 303 10.5 An Application: Adding Explanatory Output / 311 PART III Abstractions of State CHAPTER 11 Computers with Memory 333 11.1 Introduction / 333 11.2 An Example Computer Architecture / 333 11.3 Programming the SLIM / 340 Sidebar: What Can Be Stored in a Location? / 342 Sidebar: SLIM s Instruction Set / 348 11.4 Iteration in Assembly Language / 349 11.5 Recursion in Assembly Language / 357 11.6 Memory in Scheme: Vectors / 361 11.7 An Application: A Simulator for SLIM / 367

viii Out of print; full text available for free at http://www.gustavus.edu/+max/concrete-abstractions.html Contents CHAPTER 12 Dynamic Programming 379 12.1 Introduction / 379 12.2 Revisiting Tree Recursion / 380 12.3 Memoization / 388 12.4 Dynamic Programming / 398 12.5 Comparing Memoization and Dynamic Programming / 406 12.6 An Application: Formatting Paragraphs / 406 CHAPTER 13 Object-based Abstractions 420 13.1 Introduction / 420 13.2 Arithmetic Expressions Revisited / 421 13.3 RA-Stack Implementations and Representation Invariants / 432 Sidebar: Strings and Characters / 433 13.4 Queues / 446 13.5 Binary Search Trees Revisited / 453 13.6 Dictionaries / 472 CHAPTER 14 Object-oriented Programming 486 14.1 Introduction / 486 14.2 An Object-oriented Program / 487 14.3 Extensions and Variations / 511 14.4 Implementing an Object-oriented Prog. System / 517 14.5 An Application: Adventures in the Land of Gack / 543 CHAPTER 15 Java, Applets, and Concurrency 577 15.1 Introduction / 577 15.2 Java / 578 15.3 Event-Driven Graphical User Interfaces in Applets / 599 15.4 Concurrency / 616 Sidebar: Nested Calls to Synchronized Methods and Deadlock / 625 15.5 An Application: Simulating Compound Interest / 632 APPENDIX Nonstandard Extensions to Scheme 645 Bibliography 649 Index 653