Algorithmic Thinking
for
Adventurous Minds
Written By
William Xu, Raymond Xu, and Claire Xu
Copyright 2021
William Xu, Raymond Xu, and Claire Xu
All rights reserved. No part of this book may be reproduced in any form by any electronic or mechanical means (including photocopying, recording, or information storage and retrieval) without permission in writing from the publisher, except in the case of brief quotations embodied in critical reviews and certain other non-commercial uses permitted by copyright law.
Printed in the United States of America
ISBN: 9798712882892
Acknowledgement
This book would not exist without the wonderful people around us. Our teachers, mentors and friends at The Harker School and Emory University who have nurtured and influenced us in a big way.
Dr. Susan White, Stanford University, encouraged us from the start to present our unique way of visualizing the abstract concepts to a broad audience.
Dr. Catherine Fang, Carnegie Mellon University, mentored us on computational thinking and research skills.
Mr. Sanjit Singh, MIT, helped review the code and technical explanation.
Ms. Anu Datars data structure class offered us a solid foundation. Her vivid presentation and graphing were on our minds while we wrote this book.
Mr. Nicholas Manjoine and Ms. Marjorie Hazeltine inspired us into book writing with their professionalism on literature. Their feedback on the book was essential.
We feel tremendously grateful to students in our community who have actively participated in our CS and algorithm classes and online seminars over the last few years. Their valuable feedback has been incorporated in this book.
endorsement
I would recommend this book to anyone interested in a fun and engaging look at the fundamentals of algorithms. It will change your perspective.
- Jen Lee, Harvard University
It is one of a kind to bring the abstraction process to life. Fascinating.
- Bryan Ng, Stanford University
Im a visual learner. CS abstraction logic used to scare me. Sitting in William, Raymond and Claires classes changed my belief. Algorithms have a lovely side. In fact, they solve your problems. This book is a compilation of part of their class content. Hope you enjoy it like I did.
- Jeff Thomas, 9th grader at MVHS
TABLE OF CONTENTS
Introduction
Computer World is an Animal Kingdom 1
Intended Audience 8
Python Code 8
A Pictures Worth a Thousand Words 11
Magical Lens and the Land of Apple Pi 12
Mission to the Land of Apple Pi
Abstract World Through CalliLens 17
Reverse Earth Aging 19
Day 1: BestFour Landing at Greedy-Ent Mart
Landing at Greedy-End Mart 23
Decoding Nature: Fibonacci and Recursion 26
The Codephile Flowchart 32
Selling CalliLens: Greedy Coin Change 39
Greedy Approach and Its Two Properties 43
Coconut and Macadamia Nut: Fractional Knapsack 45
Day 2: Store Encounter with Dynamic Programming
Autonomous Driving to the Store 54
Properly Fed: 0-1 Knapsack Solution 55
Four Types of Knapsack Problems 57
Brute Force 59
DP and Its Two Properties 60
DP Key Concepts: States, Transitions, Memoization 66
Bottom-Up Approach 67
Top-Down Approach 76
Rejected Paper to Nobel Prize: Graphene 79
Properly Dressed: Store Coupons 82
Bottom-Up Approach 88
Top-Down Approach 90
Nacci, Nacho, Store it in Memo 91
Day 3: Gate of Summit Nurtures the World
Map, Graph, Tree, Minimum Spanning Tree 96
Building the Shortest Pipelines 108
Prims Approach 110
Kruskals Approach 113
Day 4: Seal the Gate of Traceback
Single Source Shortest Path 122
Adjacency List and Adjacency Matrix 125
Uncoil the Spring: Dijkstras Edge Relaxation 128
No Paper, No Pencil, 20 Minutes Invention 133
Day 5: Return to the Future
Polymorphic Woods Maze 143
BFS Buddies with Queue to Find the Shortest Path 150
Queue 153
DIY Maze Game 158
DFS Pairs with Stack to Locate all the Paths 165
Stack and Recursion 167
Finale
Bibliography
About the Authors
INTRODUCTION
This book is about how to work smart to avoid unnecessary work. Algorithmic thinking is about identifying the most efficient steps to solve a seemingly complex problem without detouring. It is a necessary skill for future jobs.
This book introduces many computer science terms like Fibonacci, graph, recursion, queue, stack, Greedy, Dynamic Programming, Prim, Kruskal, Dijkstra, BFS, DFS, etc. While these concepts all have rigid definitions and are not easy to grasp at a glance, this book describes them in visualizations, graphs, miniature poems, and fun facts. What a unique approach to engaging with both visual learners and reading/writing learners!
Through a magical lens, CalliLens, you will observe abstraction and recognize patterns in the Land of Apple Pi. You will adventure a series of challenges and naturally come up with the solution steps. Without forcefully knowing it, you will master the skill of algorithmic thinking.
Computer World Is an Animal Kingdom
Coming up with the right names for the characters in this book is equally important as making the algorithms and programs right. The names spark the inspiration. Spending excessive brain power gazing at the cosmos without a clue, but with a flash on the screen, the characters jump out of the computer! Computer world is an Animal Kingdom, our characters live in this Kingdom
The sky is blue; the grass is green. Deep in the forest live the BestFour:
Dark Knight
A gallant hero and adventurer, he is admired by all who meet him. He was born to lead!
Banana Split
Intelligent and enthusiastic, he brings energy to the crowd. This social butterfly will make friends with everyone!
Bubble Gum
Creative and cheerful, she brings balance to the group. This peacekeeper is a natural problem solver with an unparalleled memory.
Mighty Python
An embodiment of computer science, he brings a plethora of knowledge to the group. When it comes to Algorithms and Code, hes the one to call.
Programmers just cannot have enough animals. They added a WHOLE pack to the macOS big cat family: 10.0 Cheetah, 10.1 Puma, 10.2 Jaguar