A guide to practical programming techniques and design principles, with information on such topics as testing, debugging and timing, set representations, and string problems.Fourteen years after it was first issued, C++ expert Jon Bentley reinvents a true classic with the second edition of his Programming Pearls. Completely revised and brought up to date with all new code examples in C and C++, this book remains an exceptional tutorial for learning to think like a programmer.
The "pearls" in question center not only on choosing the right algorithms (like binary searches, sorting techniques, or sparse arrays) but also on showing how to solve problems effectively. Each chapter frames a particular programming task--such as sorting numbers, creating anagrams, or counting the words in a block of text--many drawn from Bentley's experiences in his long career as a developer. The book traces the process of arriving at a fast, efficient, and accurate solution, along with code profiling to discover what works best. After refining the correct answer, each chapter enumerates programming principles that you can use on your own.
The author also challenges you to think like an engineer, and each chapter ends with about a dozen problems to get you thinking creatively about design issues. (Sidebars on such historical topics as the first computer solutions to computer chess, spell-checking, and even architectural design help create a perspective on successful problem solving and make for a truly educational and enjoyable tour of how to become a better programmer.) Bentley also asks the reader to think analytically about the world with "back of the envelope" estimation techniques drawn from engineering. Appendices list the algorithms and code rules covered in the book, plus some sample solutions.
Fans of the first edition of this title will be pleased to see this favorite computer text brought up to date for today's faster hardware. Whether you want to improve your command of algorithms or test your problem-solving skills, the new version of Programming Pearl is a challenging, instructive, and thoroughly entertaining resource. --Richard Dragan
Topics covered: Programming and problem-solving tutorial, sorting algorithms, merge sort, bit vectors, binary searches, program correctness and testing, improving performance, engineering and problem-solving techniques, performance estimates, designing for safety, divide-and-conquer and scanning algorithms, tuning code, tips for more efficient memory usage, insertion sort, quicksort algorithms, sparse arrays, searching algorithms, binary search trees, heaps, priority queues, searching text, and generating random text.
Table of Contents
Part I: PRELIMINARIES
Column 1: Cracking the Oyster
Column 2: Aha! Algorithms
Column 3: Data Structures Programs
Column 4: Writing Correct Programs
Column 5: A Small Matter of Programming
Part II: PERFORMANCE
Column 6: Perspective on Performance
Column 7: The Back of the Envelope
Column 8: Algorithm Design Techniques
Column 9: Code Tuning
Column 10: Squeezing Space
Part III: THE PRODUCT
Column 11: Sorting
Column 12: A Sample Problem
Column 13: Searching
Column 14: Heaps
Column 15: Strings of Pearls
Appendix 1: A Catalog of Algorithms
Appendix 2: An Estimation Quiz
Appendix 3: Cost Models for Time and Space
Appendix 4: Rules for Code Tuning
Appendix 5: C++ Classes for Searching