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 a spelling suggestions 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 to “Design a two-player strategy game.”

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 the best case, we’d get a canned program with all 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. 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.

For us to get a program that does what we want, we need to feed small subproblems to Copilot and assemble those solutions into our own program. The focus of this chapter is learning how to break large problems into smaller subproblems, which is essential to being able to solve the large problems we want to solve.

7.1 Problem decomposition

7.2 Small examples of top-down design

7.3 Spelling suggestions

7.4 Spelling suggestions using top-down design

7.5 Breaking down the process subproblem

7.5.1 Getting the list of words from the word list file

7.5.2 Generating the list of all possible words

7.5.3 Generating the list of all real words

7.6 Summary of our top-down design

7.7 Implementing our functions

7.7.1 create_word_list

7.7.2 add_letter

7.7.3 delete_letter

7.7.4 change_letter

7.7.5 all_possible_words

7.7.6 all_real_words

7.7.7 get_spelling_suggestions

7.7.8 spell_check

7.8 Exercises