Decomposition
This presentation discusses Decomposition in Computer Programming. What it is, how we do it and why we would want to do it. [Slide 1] When I think about decomposition I think about dead bodies. What do dead bodies and computer programming have in common? Not much, thank goodness. There is absolutely nothing rotten about computer programming. When we talk about decomposition in computer programming we mean the other definition of decomposition, breaking something into its component parts. [Slide 2] When you create a computer program you're just writing a list of steps or instructions that you want the computer to perform to solve the problem. Here's what you generally do.
First you identify the problem you want to solve. Then you break it into its separate parts. This is called decomposition. Sometimes you have to simplify the problem first and that's called abstraction. Once you have decomposed the problem you create a code for each part and you combine the pieces of the code to create the program. [Slide 3] So decomposition is sort of dividing and conquering the problem. Let's look at the steps.
First you identify the parts of the problem. The pieces that you can break it into. They have to be about the same level of detail. They should be able to be performed separately or written up separately and when they combine together they should solve the original problem. Once you have identified the parts or components of your problem then you write steps for solving each bit. Finally, you combine the steps for each part to solve the problem.
Normally, what I would do here is to look at a piece of code and explain how the problem is decomposed but we don't really know enough programming yet to do that. Let's look at a different type of problem. [Slide 4] Okay, here's my problem. I want cake! I absolutely desperately want cake but I need to make the cake if I'm going to have it because I can't get to the store. Okay, let's decompose this problem.
The first part of decomposition is breaking the problem down into its component parts. Remember, each component part has to be roughly the same level of detail and can be performed separately and when you combine them together you solve your problem. The component parts of I want cake or making a cake are to gather the equipment, gather the ingredients, measure the ingredients, mix the ingredients and bake the cake. Now, it's really important to know that someone else might have decomposed the problem differently and that's okay. Many problems can be decomposed in different ways and each one is equally valid.
[Slide 5] The second part to decomposition is writing the steps for each component part. Our first part was gathering the equipment so we would write the steps for that. The first step would be get the mixing bowls. Then we'd get the small bowls you need to measure the ingredients into. Then get the cake pans, get the mixer, get the measuring spoons, get the measuring cups. Let's look at the next component part. [Slide 6] The next part is gathering the ingredients. Okay, I go get the flour, get the sugar, get the oil, the vanilla, the eggs, the baking powder, the milk, the pam. That's it. That's all the ingredients I need to make cake.
[Slide 7] In this part of the problem we would measure the ingredients so I would write down measuring 1-1/2 cups of flour, putting the flour in a small bowl, measure one cup of sugar, and putting it in another bowl and you get the idea. We would continue writing the steps for parts D and E and then we would have all the steps we needed to make cake. [Slide 8]The last part of decomposition is putting the pieces back together. Okay, so we put the pieces back together. We put all the steps for gathering the equipment and gathering the ingredients and measuring the ingredients, mixing the ingredients and baking the cake. We'd line up all those steps in the right order. Then we would carry out the steps which would be the same as running the program if we had created a program and voila! We would have cake and we would have solved our problem.
[Slide 9]The advantages of decomposition. It's certainly easier to think about smaller pieces of a problem than the whole problem at once. When you decompose a problem different people can work on each of the component parts and this speeds up programming. If we're looking at our cake analogy someone might gather the ingredients while someone else is measuring them. This might speed up the whole process and if you employed parallel processing it might be possible to speed up the execution. In this case, parallel processing would be sort of like preheating the oven while you're preparing the batter. That way you don't have to wait for the oven to preheat once you prepare the batter.
[Slide 10]There are certainly some disadvantages to decomposition. The first and most important disadvantage is that computers are just plain stupid. They do exactly what you tell them even if it's wrong and they do those steps in exactly the order that you tell them to do them even if that's wrong too. One of the disadvantages of decomposition is that you have to tell them exactly what to do and exactly when to do it and sometimes that can be hard. Also sometimes problems can't be decomposed without simplifying them first because they're either too difficult or maybe they’re not well understood and sometimes when you put the pieces back together again it just doesn't work.
[Slide 11]In summary, decomposition is breaking the problem into its component parts. You write the steps or the code for each component part and then you put the pieces back together again to make a program and to solve the problem. This is good because it's easier to think about problems when you break them up and also program and execution can be faster when you do this but remember computers are just plain stupid. They do exactly what you tell them to do and exactly how you tell them to do it and sometimes when you put the pieces back together again it just doesn't work.
Decomposition_v2 / Page 1 of 3