7 Problem decomposition

 

This chapter covers

  • Understanding problem decomposition and why we need to do it
  • Using top-down design to carry out problem decomposition and write programs
  • Writing an authorship identification program using top-down design

In chapter 3, we talked about why we shouldn’t ask Copilot to solve big problems. Imagine what could happen if we asked Copilot, “Write a program to determine the author of a book.”

In the best case, we’d get a canned program with all of the decisions made for us. That program may not match what we wanted. Part of the power of being a programmer is customizing what we’re creating. To do this, we need to feed small subproblems to Copilot and assemble those solutions into a program of our own. Even if we didn’t want to customize anything, what would we do if the program from Copilot had flaws? It would be difficult for us to fix a large program that we don’t understand.

In the worst case, Copilot wouldn’t do anything useful. We observe this sometimes when Copilot gives us comments again and again but never provides us with real code.

In this chapter, we will learn how to break large problems into smaller ones. We can then use Copilot to solve each of the small subproblems, thereby solving the large problem that we ultimately care about solving.

7.1 Problem decomposition

7.2 Small examples of top-down design

7.3 Authorship identification

7.4 Authorship identification using top-down design

7.5 Breaking down the process subproblem

7.5.1 Figuring out the signature for the mystery book

7.6 Summary of our top-down design

7.7 Implementing our functions

7.7.1 clean_word

7.7.2 average_word_length

7.7.3 different_to_total

7.7.4 exactly_once_to_total

7.7.5 split_string

7.7.6 get_sentences

7.7.7 average_sentence_length

7.7.8 get_phrases

7.7.9 average_sentence_complexity

7.7.10 make_signature

7.7.11 get_all_signatures

7.7.12 get_score

7.7.13 lowest_score

7.7.14 process_data