# New Mexico Computer Science For All Decomposition in Computer Programming Maureen Psaila-Dombrowski.

## Presentation on theme: "New Mexico Computer Science For All Decomposition in Computer Programming Maureen Psaila-Dombrowski."— Presentation transcript:

New Mexico Computer Science For All Decomposition in Computer Programming Maureen Psaila-Dombrowski

Decomposition – Yuck! There is nothing rotten about computer programming We mean the other definition – breaking into parts

How to Create a Computer Program Computer program = list of instructions To Write a Computer Program  Identify the problem  Break it into separate parts (Decomposition)  Sometimes the problem must be simplified first (Abstraction)  Create the code for each part  Combine the pieces of code to create the program

Decomposition Steps Divide and Conquer Step 1: Identify the parts ▫Roughly the same level of detail ▫Can be written up separately ▫Combine to solve the original problem Step 2: Write the steps for each part Step 3: Combine the steps for each part to solve the problem

Example: I Want Cake! Step 1: Identify the Components or Parts A.Gather the Equipment B.Gather the Ingredients C.Measure the Ingredients D.Mix the Ingredients E.Bake the Cake

Example: I Want Cake! (continued) Step 2: Write the Steps ▫A. Gather the Equipment 1.Get the mixing bowls 2.Get small bowls to measure ingredients into 3.Get cake pans 4.Get mixer 5.Get measuring spoons 6.Get measuring cups

Example: I Want Cake! (continued) Step 2: Write the Steps (continued) ▫B. Gather the Ingredients 1.Get the flour 2.Get the sugar 3.Get the oil 4.Get the vanilla 5.Get the eggs 6.Get the baking powder 7.Get the milk 8.Get the pam

Example: I Want Cake! (continued) Step 2: Write the Steps (continued) ▫C. Measure the Ingredients 1.Measure 1 ½ cups flour 2.Put flour in small bowl 3.Measure1 cup sugar 4.Put in another bowl 5.…. You get the idea (continue for parts D and E)

Example: I Want Cake! (continued) Step 3: Put the pieces back together A.Gather the Equipment B.Gather the Ingredients C.Measure the Ingredients D.Mix the Ingredients E.Bake the Cake Then carry out all the small steps………. ………… And when you are done you have Cake!

Advantages of Decomposition Easier to think about smaller pieces of the problem than the whole problem at once. Different people can work on each part (speeds up programming). Someone might gather the ingredients while someone else measure them. Parallel Processing might be possible (speeds up execution). You could preheat the oven while you are preparing the batter.

Disadvantages of Decomposition Computers are Stupid ▫They do exactly what you tell them to do even if it is WRONG. ▫They do the steps in exactly the order you tell them to do even if that’s WRONG too! Sometimes problems cannot be decomposed without simplifying them first ▫Too difficult ▫Not well understood Sometimes when you put the pieces back together it does not work!

Summary Decomposition  Break the problem into its components  Write the steps (code) for each component  Put the pieces together to make the program and solve the problem! This is good because  It is easier to think about  Programming and execution can be faster But Remember-  Computers are stupid - they do:  Exactly what you tell them to do  Exactly how you tell them to do it  Sometimes putting the pieces together doesn’t work

Download ppt "New Mexico Computer Science For All Decomposition in Computer Programming Maureen Psaila-Dombrowski."

Similar presentations