Book Grokking Algorithms

My Notes on Algorithms book

Book: Grokking Algorithms

About

Book: “Grokking Algorithms”: A Friendly Guide to Problem Solving

Have you ever wondered how your computer manages to search through billions of web pages in seconds, or how a navigation app finds the fastest route to your destination? The answer lies in algorithms – the step-by-step procedures that power our digital world. If you’ve ever been curious about how these work, “Grokking Algorithms” by Aditya Y. Bhargava is a great place to start.

What to Expect

This book isn’t a dry, theoretical text. It’s designed to be an accessible, illustrated guide that makes complex topics easy to grasp. The author’s approach emphasizes visual learning, using diagrams and code examples in Python to explain concepts. You don’t need to be a computer science expert to benefit from it. The book focuses on practical, useful algorithms that you’re likely to encounter in software development.

Key Concepts and Chapters

The book covers fundamental topics, building from basic to more complex concepts, and encourages you to try out the code:

  • Introduction to Algorithms (Chapter 1): You’ll start with a practical algorithm, binary search, and learn how to analyze algorithm speed using Big O notation. This chapter shows how a well-chosen algorithm can dramatically improve the efficiency of your code. You’ll see how binary search drastically reduces the number of steps needed to find an item in a sorted list. Logarithms are also explained, as they are fundamental to understanding the efficiency of binary search.
  • Arrays and Linked Lists (Chapter 2): You’ll learn about two fundamental data structures that are used throughout the book, and in programming generally. Arrays provide fast random access to elements, but have slow insertion and deletion, while linked lists have faster insertion/deletion, but slower random access. Understanding these trade-offs is key to selecting appropriate data structures for different tasks.
  • Recursion (Chapter 3): This chapter explains recursion, a technique where a function calls itself to solve a problem. You will learn how to break a problem down into a base case and a recursive case. The concept of the call stack is also covered, which is essential for understanding how recursion works.
  • Quicksort (Chapter 4): Here, you’ll dive into the divide-and-conquer strategy, which is a way of approaching problem solving, not just an algorithm. Quicksort is an efficient sorting algorithm that is an example of a divide and conquer algorithm. You’ll learn that, in the average case, quicksort has a time complexity of O(n log n), which is significantly faster than selection sort O(n^2). You’ll also learn the difference between the average and worst case for quicksort.
  • Hash Tables (Chapter 5): This chapter explores hash tables, which are very efficient data structures, also known as hash maps or dictionaries, that map keys to values. You’ll learn how they’re used for tasks like duplicate detection and caching. The chapter also discusses collisions and hash functions and how they impact performance.
  • Breadth-First Search (Chapter 6): This chapter introduces graphs as a way to model networks, and uses the Breadth-First Search (BFS) algorithm to find the shortest path between two nodes. BFS uses a queue to explore nodes level by level, making sure the shortest path is found. You’ll also learn about the difference between directed and undirected graphs.
  • Dijkstra’s Algorithm (Chapter 7): You will learn how to find the shortest path in a weighted graph using Dijkstra’s algorithm. You’ll see how this algorithm works, and also why it is not compatible with graphs that contain negative edges.
  • Greedy Algorithms (Chapter 8): You will be introduced to greedy algorithms, which are used for optimization and are very efficient, and some of their limitations. The book explains what NP-complete problems are, which are problems for which there is no known fast algorithm.
  • Dynamic Programming (Chapter 9): This chapter introduces the concept of dynamic programming which is a method of approaching optimization problems by recursively breaking them down into subproblems, and storing previously calculated results in a table to reduce computational effort. The book gives the example of finding the longest common substring.
  • K-Nearest Neighbors (Chapter 10): You’ll learn about k-nearest neighbors (KNN), a machine learning technique used for classification and regression. The importance of feature extraction, and choosing the right features when using KNN, is highlighted.
  • Next Steps (Chapter 11): The book concludes with an overview of 10 interesting algorithms for further exploration, which include, amongst others: tree data structures, inverted indexes, Bloom filters, HyperLogLog, SHA algorithms, and the Diffie-Hellman key exchange.

Key Points to Remember

  • Visual Learning: The book’s emphasis on illustrations and diagrams makes complex topics easier to understand.
  • Practical Approach: The focus is on algorithms that are useful in everyday programming tasks.
  • Big O Notation: You’ll learn how to analyze algorithm performance using Big O notation, which is crucial for writing efficient code.
  • Data Structures: The book introduces various data structures such as arrays, linked lists, hash tables, queues, and graphs, each with its own strengths and weaknesses.
  • Problem-Solving Techniques: The book teaches you different ways of approaching problems, such as divide and conquer, recursion, and dynamic programming, giving you a toolbox of methods.

Who Should Read This Book?

“Grokking Algorithms” is perfect for:

  • Hobbyist programmers
  • Students in computer science or programming courses
  • Graduates who want to refresh their knowledge
  • Professionals in other fields who are interested in programming
  • Anyone curious about how algorithms work

Where to Find the Code

The code examples in the book are available on GitHub: github.com/egonschiele/grokking_algorithms. The repository includes examples in multiple languages.

Going Deeper

In chapter 11, the book introduces some interesting algorithms for further exploration. These include:

  • Tree data structures
  • Inverted indexes
  • Bloom filters
  • HyperLogLog
  • SHA algorithms
  • Diffie-Hellman key exchange

Take some of these that interests to you and go to another sources to explore in deeper detail.

Final Thoughts

“Grokking Algorithms” provides a gentle yet comprehensive introduction to the world of algorithms. It’s a great resource for anyone looking to improve their understanding of computer science concepts and how they’re applied in practice. It empowers you to think algorithmically and solve problems more efficiently.

Let me know if you’d like any revisions or additional details!

References

0%