ebook img

The Recursive Book of Recursion: Ace the Coding Interview with Python and JavaScript PDF

331 Pages·2022·10.166 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Recursive Book of Recursion: Ace the Coding Interview with Python and JavaScript

THE RECURSIVE BOOK OF RECURSION T H E R E C U R S I V E B O O K O F R E C U R S I O N Ace the Coding Interview with Python and JavaScript by Al Sweigart San Francisco THE RECURSIVE BOOK OF RECURSION. Copyright © 2022 by Al Sweigart. Some rights reserved. This work is licensed under the Creative Commons Attribution-NonCommercial- ShareAlike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/ by-nc-sa/3.0/us or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. First printing 26 25 24 23 22 1 2 3 4 5 ISBN-13: 978-1-71850-202-4 (print) ISBN-13: 978-1-71850-203-1 (ebook) Publisher: William Pollock Production Manager: Rachel Monaghan Production Editor: Miles Bond Developmental Editor: Frances Saux Cover Illustrator: James L. Barry Interior Design: Octopod Studios Technical Reviewer: Sarah Kuchinsky Copyeditor: Sharon Wilkey Compositor: Maureen Forys, Happenstance Type-O-Rama Proofreader: Audrey Doyle For information on distribution, bulk sales, corporate sales, or translations, please contact No Starch Press, Inc. directly at [email protected] or: No Starch Press, Inc. 245 8th Street, San Francisco, CA 94103 phone: 1.415.863.9900 www.nostarch.com Library of Congress Cataloging-in-Publication Data Library of Congress Control Number: 2022932456 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. To Jack, who held up a mirror in front of my mirror About the Author Al Sweigart is a software developer, fellow of the Python Software Foundation, and author of several programming books with No Starch Press, including the worldwide bestseller Automate the Boring Stuff with Python. His Creative Commons licensed works are available at https://www .inventwithpython.com. About the Technical Reviewer Sarah Kuchinsky, MS, is a corporate trainer and consultant. She uses Python for a variety of applications, including health systems modeling, game development, and task automation. Sarah is a co-founder of the North Bay Python conference, tutorials chair for PyCon US, and lead orga- nizer for PyLadies Silicon Valley. She holds degrees in management science as well as in engineering and mathematics. BRIEF CONTENTS Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xix PART I: UNDERSTANDING RECURSION . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Chapter 1: What Is Recursion? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Chapter 2: Recursion vs . Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21 Chapter 3: Classic Recursion Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45 Chapter 4: Backtracking and Tree Traversal Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . .71 Chapter 5: Divide-and-Conquer Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93 Chapter 6: Permutations and Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123 Chapter 7: Memoization and Dynamic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . .151 Chapter 8: Tail Call Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163 Chapter 9: Drawing Fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .175 PART II: PROJECTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .201 Chapter 10: File Finder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .203 Chapter 11: Maze Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .215 Chapter 12: Sliding-Tile Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .231 Chapter 13: Fractal Art Maker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .259 Chapter 14: Droste Maker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .283 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .297

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.