Series Editors. Editorial Board

Similar documents
Guide to Teaching Computer Science

MARE Publication Series

Lecture Notes on Mathematical Olympiad Courses

PRODUCT PLATFORM AND PRODUCT FAMILY DESIGN

Perspectives of Information Systems

International Series in Operations Research & Management Science

US and Cross-National Policies, Practices, and Preparation

Language properties and Grammar of Parallel and Series Parallel Languages

CS 1103 Computer Science I Honors. Fall Instructor Muller. Syllabus

Course Content Concepts

WSU Five-Year Program Review Self-Study Cover Page

Erkki Mäkinen State change languages as homomorphic images of Szilard languages

Multimedia Application Effective Support of Education

EDUCATION IN THE INDUSTRIALISED COUNTRIES

Lecture Notes in Artificial Intelligence 4343

IMPLEMENTING EUROPEAN UNION EDUCATION AND TRAINING POLICY

Advances in Mathematics Education

Education for an Information Age

A R "! I,,, !~ii ii! A ow ' r.-ii ' i ' JA' V5, 9. MiN, ;

GACE Computer Science Assessment Test at a Glance

Communication and Cybernetics 17

We are strong in research and particularly noted in software engineering, information security and privacy, and humane gaming.

COMPUTATIONAL COMPLEXITY OF LEFT-ASSOCIATIVE GRAMMAR

A General Class of Noncontext Free Grammars Generating Context Free Languages

AUTONOMY. in the Law

Linking Task: Identifying authors and book titles in verbose queries

Conducting the Reference Interview:

Machine Learning from Garden Path Sentences: The Application of Computational Linguistics

Second Language Learning and Teaching. Series editor Mirosław Pawlak, Kalisz, Poland

Proof Theory for Syntacticians

IMPROVING STUDENTS WRITING SKILL USING PAIR CHECK METHOD AT THE SECOND GRADE STUDENTS OF SMP MUHAMMADIYAH 3 JETIS IN THE ACADEMIC YEAR OF 2015/2016.

Navigating the PhD Options in CMS

Parsing of part-of-speech tagged Assamese Texts

An OO Framework for building Intelligence and Learning properties in Software Agents

Self Study Report Computer Science

Lecture Notes in Artificial Intelligence 7175

Discriminative Learning of Beam-Search Heuristics for Planning

Towards a MWE-driven A* parsing with LTAGs [WG2,WG3]

Some Principles of Automated Natural Language Information Extraction

TIMSS ADVANCED 2015 USER GUIDE FOR THE INTERNATIONAL DATABASE. Pierre Foy

The Strong Minimalist Thesis and Bounded Optimality

CS 101 Computer Science I Fall Instructor Muller. Syllabus

University of Groningen. Systemen, planning, netwerken Bosman, Aart

Developing Grammar in Context

Math-U-See Correlation with the Common Core State Standards for Mathematical Content for Third Grade

Analysis of Enzyme Kinetic Data

PH.D. IN COMPUTER SCIENCE PROGRAM (POST M.S.)

Module 12. Machine Learning. Version 2 CSE IIT, Kharagpur

Data Structures and Algorithms

Developing a TT-MCTAG for German with an RCG-based Parser

The Internet as a Normative Corpus: Grammar Checking with a Search Engine

Machine Learning and Data Mining. Ensembles of Learners. Prof. Alexander Ihler

LIFELONG LEARNING PROGRAMME ERASMUS Academic Network

THE UNIVERSITY OF SYDNEY Semester 2, Information Sheet for MATH2068/2988 Number Theory and Cryptography

Lecture 1: Machine Learning Basics

Notes on The Sciences of the Artificial Adapted from a shorter document written for course (Deciding What to Design) 1

Digital Fabrication and Aunt Sarah: Enabling Quadratic Explorations via Technology. Michael L. Connell University of Houston - Downtown

RANKING AND UNRANKING LEFT SZILARD LANGUAGES. Erkki Mäkinen DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A ER E P S I M S

Teachers response to unexplained answers

A Version Space Approach to Learning Context-free Grammars

COMMUNICATION-BASED SYSTEMS

INFORMATION AND COMMUNICATION TECHNOLOGIES AND REAL-LIFE LEARNING

ISSN Volume 3 No. 2, August 2005 EDITORS-IN-CHIEF

Higher Education / Student Affairs Internship Manual

(Sub)Gradient Descent

AQUA: An Ontology-Driven Question Answering System

ABSTRACT. A major goal of human genetics is the discovery and validation of genetic polymorphisms

content First Introductory book to cover CAPM First to differentiate expected and required returns First to discuss the intrinsic value of stocks

Grammars & Parsing, Part 1:

A. True B. False INVENTORY OF PROCESSES IN COLLEGE COMPOSITION

JEFFERSON COLLEGE COURSE SYLLABUS BUS 261 BUSINESS COMMUNICATIONS. 3 Credit Hours. Prepared by: Cindy Rossi January 25, 2014

Economics 201 Principles of Microeconomics Fall 2010 MWF 10:00 10:50am 160 Bryan Building

An Introduction to Simio for Beginners

Instructor Experience and Qualifications Professor of Business at NDNU; Over twenty-five years of experience in teaching undergraduate students.

10.2. Behavior models

Online Marking of Essay-type Assignments

Advanced Grammar in Use

What s in a Step? Toward General, Abstract Representations of Tutoring System Log Data

Course Syllabus for Math

Iraqi EFL Students' Achievement In The Present Tense And Present Passive Constructions

TABLE OF CONTENTS TABLE OF CONTENTS COVER PAGE HALAMAN PENGESAHAN PERNYATAAN NASKAH SOAL TUGAS AKHIR ACKNOWLEDGEMENT FOREWORD

Macroeconomic Theory Fall :00-12:50 PM 325 DKH Syllabus

Parallel Evaluation in Stratal OT * Adam Baker University of Arizona

Competition in Information Technology: an Informal Learning

A MULTI-AGENT SYSTEM FOR A DISTANCE SUPPORT IN EDUCATIONAL ROBOTICS

The University of Texas at Tyler College of Business and Technology Department of Management and Marketing SPRING 2015

Writing Research Articles

Computer Science (CS)

Improving Fairness in Memory Scheduling

Developing Language Teacher Autonomy through Action Research

PROVIDING AND COMMUNICATING CLEAR LEARNING GOALS. Celebrating Success THE MARZANO COMPENDIUM OF INSTRUCTIONAL STRATEGIES

IT Students Workshop within Strategic Partnership of Leibniz University and Peter the Great St. Petersburg Polytechnic University

Testing A Moving Target: How Do We Test Machine Learning Systems? Peter Varhol Technology Strategy Research, USA

Presentation Advice for your Professional Review

Given a directed graph G =(N A), where N is a set of m nodes and A. destination node, implying a direction for ow to follow. Arcs have limitations

SAM - Sensors, Actuators and Microcontrollers in Mobile Robots

Mathematical Induction Examples And Solutions

Evolution of Collective Commitment during Teamwork

Syllabus for Philosophy of Mathematics Thomas Donaldson; Winter Quarter, 2015

MODULE 4 Data Collection and Hypothesis Development. Trainer Outline

Transcription:

Series Editors Editorial Board

ABC

Alexander Shen Laboratoire d Informatique Fondamentale de Marseille (LIF) CNRS, Université delaméditerranée, Université deprovence CMI 39 Rue Joliot-Curie 13453 Marseille Cedex 13 France alexander.shen@lif.univ-mrs.fr and Russian Academy of Sciences Institute for Information Transmission Problems Bolshoy Karetny per. 19 Moscow, GSP-4, 127994 Russia Series Editors Jonathan M. Borwein, FRSC Professor Laureate Director Centre for Computer Assisted Research Mathematics and its Applications, CARMA School of Mathematical & Physical Sciences University of Newcastle Callaghan NSW 2308 Australia Jonathan.Borwein@newcastle.edu.au Helge Holden Department of Mathematical Sciences Norwegian University of Science and Technology Alfred Getz vei 1 NO-7491 Trondheim Norway holden@math.ntnu.no ISSN 1867-5506 e-issn 1867-5514 ISBN 978-1-4419-1747-8 e-isbn 978-1-4419-1748-5 DOI 10.1007/978-1-4419-1748-5 Springer New York Dordrecht Heidelberg London Library of Congress Control Number: 2009942420 Mathematics Subject Classification (2000): 65K05, 65Yxx, 90Cxx, 68-01, 68W40 1st edition: c Birkhäuser 1997 Reprint of 1st edition in series: Modern Birkhäuser Classics c Birkhäuser 2008 2nd edition: c Springer Science+Business Media, LLC 2010 All rights reserved. This work may not be translated or copied in whole or in part without the written permission of the publisher (Springer Science+Business Media, LLC, 233 Spring Street, New York, NY 10013, USA), except for brief excerpts in connection with reviews or scholarly analysis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed is forbidden. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com)

To the memory of Anna Pogossiants

Contents Preface to the second edition....................................... xi 1 Variables, expressions, assignments............................. 1 1.1 Problems without arrays..................................... 1 1.2 Arrays.................................................... 15 1.3 Inductive functions......................................... 28 2 Generation of combinatorial objects............................ 33 2.1 Sequences................................................. 33 2.2 Permutations.............................................. 34 2.3 Subsets................................................... 35 2.4 Partitions................................................. 37 2.5 Gray codes and similar problems.............................. 39 2.6 Some remarks............................................. 44 2.7 Counting.................................................. 46 3 Tree traversal (backtracking).................................. 49 3.1 Queens not attacking each other: position tree................... 49 3.2 Tree traversal.............................................. 50 3.3 Queens: position tree implementation.......................... 56 3.4 Backtracking in other problems............................... 59 4 Sorting..................................................... 61 4.1 Quadratic algorithms........................................ 61 4.2 Sorting in n log n operations................................. 62 4.3 Applications of sorting...................................... 69 4.4 Lower bound for the number of comparisons.................... 70 4.5 Problems related to sorting................................... 72 vii

viii Contents 5 Finite-state algorithms in text processing......................... 77 5.1 Compound symbols, comments, etc............................ 77 5.2 Numbers input............................................. 79 6 Data types.................................................. 83 6.1 Stacks.................................................... 83 6.2 Queues................................................... 89 6.3 Sets...................................................... 97 6.4 Priority queues............................................. 100 7 Recursion................................................... 103 7.1 Examples................................................. 103 7.2 Trees: recursive processing.................................. 106 7.3 The generation of combinatorial objects; search................. 109 7.4 Other applications of recursion............................... 113 8 Recursive and non-recursive programs.......................... 119 8.1 Table of values (dynamic programming)....................... 119 8.2 Stack of postponed tasks..................................... 123 8.3 Difficult cases............................................. 126 9 Graph algorithms............................................ 129 9.1 Shortest paths.............................................. 129 9.2 Connected components, breadth- and depth-first search........... 133 10 Pattern matching............................................. 139 10.1 Simple example............................................ 139 10.2 Repetitions in the pattern.................................... 142 10.3 Auxiliary lemmas.......................................... 143 10.4 Knuth Morris Pratt algorithm................................ 144 10.5 Boyer Moore algorithm..................................... 146 10.6 Rabin Karp algorithm...................................... 148 10.7 Automata and more complicated patterns....................... 149 10.8 Suffix trees................................................ 156 11 Games analysis.............................................. 167 11.1 Game examples............................................ 167 11.2 Game cost................................................. 169 11.3 Computing the game cost by backtracking...................... 176 11.4 Alpha-beta pruning......................................... 178 11.5 A retrospective analysis..................................... 182

Contents ix 12 Optimal coding.............................................. 185 12.1 Codes.................................................... 185 12.2 The Kraft McMillan inequality............................... 186 12.3 Huffman code............................................. 189 12.4 Shannon Fano code........................................ 191 13 Set representation. Hashing.................................... 195 13.1 Hashing with open addressing................................ 195 13.2 Hashing using lists......................................... 198 14 Sets, trees, and balanced trees.................................. 203 14.1 Set representation using trees................................. 203 14.2 Balanced trees............................................. 210 15 Context-free grammars....................................... 221 15.1 General parsing algorithm................................... 221 15.2 Recursive-descent parsing................................... 226 15.3 Parsing algorithm for LL(1)-grammars......................... 236 16 Left-to-right parsing (LR)..................................... 243 16.1 LR-processes.............................................. 243 16.2 LR(0)-grammars........................................... 248 16.3 SLR(1)-grammars.......................................... 252 16.4 LR(1)-grammars, LALR(1)-grammars......................... 253 16.5 General remarks about parsing algorithms...................... 256 Further reading.................................................. 257 Appendix: C and Pascal examples.................................. 259 Index........................................................... 267

Preface to the Second Edition Somebody once said that one may prove the correctness of an algorithm, but not of a program. One of the main goals of this book is to convince the reader that things are not so bad. A well-known programmer, C.A.R. Hoare, said that the beauty of a program is not an additional benefit but a criterion that separates success from failure. If, while solving problems in this book, you come to appreciate the beauty of a well-written program with each part in its correct place, the author s goal will have been reached. Theoretically this book can be used to study programming without a computer: one could write (correct) programs with pencil and paper. But in practice the ability to run the programs is a challenge and a reward that makes programming a fun. We have utilized the problem-solution format. Some chapters are collections of problems having a common topic, while others are devoted to one specific algorithm (e.g., chapter 16 covers LR(1)-parsing). The chapters are more or less independent, but the concluding chapters are more difficult. Chapters 1 7 cover material usually included in undergraduate courses while chapters 15 16 are more appropriate for a graduate compiler course. In each chapter we have tried to give problems at different levels starting with easy exercises. Problems are usually provided with solutions, answers or hints. However, we strongly recommend to read the solution only after the reader makes a good faith attempt to solve it independently. The book is restricted to micro-programming leaving aside another very important topic: how to split the program into a manageable parts with nice interfaces between them. (Probably this can be learned only by reading and modifying rather large programs.) Pascal is used as a programming language; though being outdated, it is reasonably clear, so the readers familiar with any other procedural language (C, Modula, Oberon, etc.) will encounter no difficulties. For the reader s convenience, a short appendix is added that lists basic differences between Pascal and C. It is intended to help the reader who knows C to understand the program notation in the book (but cannot replace textbooks on C). xi

xii Preface to the second edition Most of the problems, of course, are well known. References are rare, but absence of references does not mean that the problem or algorithm is new. However, we hope that in some cases the algorithm or the proof is explained better than what is found in other sources. This book is addressed both to the ambitious student who wants to test and improve his/her skills and to the instructor looking for problems for his/her class. I thank all the people I met while teaching programming (first of all, my former students from 57th school and A.G. Kushnirenko, who was my programming teacher) and all readers that sent me corrections for the preliminary versions of this book (especially Yu.V. Matijasevich). I also thank American Mathematical Society (former Soviet Union aid fund), International Science Foundation, Open Society Foundation, MIT, University of Bordeaux, Bonn University, the Rosenbaum Foundation, INTAS, University of Provence, CNRS, Institute of Problems of Information Transmission and even the Russian government for support during writing this book. I thank Ann Kostant, Elizabeth Loew and the other nice people at Birkhäuser and Springer for their help. Tom Scavo did a great job correcting my English (as well as several other errors) but in no case should he be blamed for the remaining mistakes. Peter Panov helped to prepare the second edition by translating new material in chapters 10 12 and language editing. The Russian version of this book is freely distributable as a TEX source and camera-ready copy; please look at ftp://ftp.mccme.ru/users/shen/progbook and/or contact the author (e-mail addresses: shen@landau.ac.ru, shen@mccme.ru, sasha.shen@gmail.com, alexander.shen@lif.univ-mrs.fr) for details. I d be grateful if bug reports could be sent to the same addresses. Alexander Shen September, 2009