Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 1: Principles of Computer Science

Similar presentations


Presentation on theme: "Unit 1: Principles of Computer Science"— Presentation transcript:

1 Unit 1: Principles of Computer Science
Decomposition in Computer Programming Mr Chandler This presentation discusses decomposition in computer programming, what it is, how we do it and why we would want to do it

2 Decomposition – Yuck! There is nothing rotten about computer programming We mean the other definition – breaking into parts OK so when I think about decomposition I think about, well, dead bodies. So what do dead bodies and computer programming have in common - not much thank goodness. there is absolutly nothing rotten about computer programming. When we talk about decomposition in computer programming we mean the other definition of decomposition – breaking into something into its component parts

3 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 So remember that a computer program is just a list of steps or instructions that you want the computer to perform to solve a problem. So when you write a computer program you need to know what those steps are No problem, it’s a piece of cake. Here what you need to do Identify the problem you want the computer to solve Break it into components or steps that can be solved (that is DECOMPOSITION which we will be discussing in this video). Sometimes the problem has to be simplified first before you can break it down into steps (that is called abstraction which we will talk about in another video Then create code for each component or part Then you combine the pieces of code to create the computer program!

4 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 So you can think of Decomposition as dividing and conquering the problem. When you decompose a problem, the first thing you do is identify the parts of the problem. Each of these parts should have about the same level of detail and you should be able to write them up or do them separately. When you combine the pieces, they should solve the original problem. After you break the problem down into parts, the next step in decomposition is writing out the steps in code for each part. Then you put all the steps together in the correct order and you get the code that solves the problem So what we need to do is look at an example… but we don’t know enough yet to look at a programming example so lets decompose a different type of problem

5 Example: I Want Cake! Step 1: Identify the Components or Parts
Gather the Equipment Gather the Ingredients Measure the Ingredients Mix the Ingredients Bake the Cake Lets look at an example. I want cake. I absolutely, desperately want cake but I need to make a cake if I want it. Lets decompose the problem. The first step is to break the problem into its components or parts. So the the components of my problem of wanting cake are.. … Roughly the same level of detail Can be written up separately Combine to solve the original problem It is important to know that someone else might decompose the problem differently and that is OK too.

6 Example: I Want Cake! (continued)
Step 2: Write the Steps A. Gather the Equipment Get the mixing bowls Get small bowls to measure ingredients into Get cake pans Get mixer Get measuring spoons Get measuring cups So now we proceed to step two of the decomposition process – writing steps for each part. Lets look at the fist part – gathering the equipment. Here are the steps ….

7 Example: I Want Cake! (continued)
Step 2: Write the Steps (continued) B. Gather the Ingredients Get the flour Get the sugar Get the oil Get the vanilla Get the eggs Get the baking powder Get the milk Get the pam Lets look at the next part of the decomposition of my cake problem – gathering the ingredients

8 Example: I Want Cake! (continued)
Step 2: Write the Steps (continued) C. Measure the Ingredients Measure 1 ½ cups flour Put flour in small bowl Measure1 cup sugar Put in another bowl …. You get the idea (continue for parts D and E) And now part three – measuring the ingredients…. Well you get the idea. You would do the same for parts D and E

9 Example: I Want Cake! (continued)
Step 3: Put the pieces back together Gather the Equipment Gather the Ingredients Measure the Ingredients Mix the Ingredients Bake the Cake Then carry out all the small steps………. ………… And when you are done you have Cake! The next step in the decomposition of my wanting cake problem is putting the pieces and their steps back together. Then we would carry out the steps – which would be equivalent to running the program and voila when we are done we would Have Cake

10 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. So that is what decomposition looks like… some advantages of decomposition are

11 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!

12 Summary Decomposition This is good because But Remember-
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 "Unit 1: Principles of Computer Science"

Similar presentations


Ads by Google