A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition
by Jay Wengrow
Chapter 11
These are the solutions to the exercises found in the section, Exercises. The solutions provided here are in Ruby, but you can find the solutions in JavaScript and Python in the code download.[11]
-
Let’s call our function character_count. The first step is to pretend that the character_count function has already been implemented.
Next, we need to identify the subproblem. If our problem is the array, ["ab", "c", "def", "ghij"], then our subproblem can be the same array missing one string. Let’s specifically say that our subproblem is the array minus the first string, which would be ["c", "def", "ghij"].
Now, let’s see what happens when we apply the “already implemented” function on the subproblem. If we were to call character_count(["c", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access