Break Down a Problem

Grey overlay

Pink

Green

Blue

Cream

Liliac

Purple

Yellow

1 Objectives

Developing Algorithms learning strand, specifically:

  • develop problem solving skills by decomposition
  • learn how to represent algorithms using flowchart
  • learn how to represent algorithms using pseudo-code
  • Understand how abstraction can help solving complex problems

Developing Programming and Development learning strand, specifically:

  • implement solutions using selection and repetition
  • develop further understanding that programming bridges the gap between algorithmic solutions and computers

2 Decomposition

Learn It - divide and conquer

  • In the last lesson we looked at how to use structured English to describe specific steps to solve a problem.
  • Sometimes, the problem is complex or seemingly complex. A common approach to solve a complex problem is to break down the problem into smaller, easier to solve problems. After we solved each of those smaller problems, the complex problem is solved.
  • The above approach to problem solving is called divid-and-conquer.
  • In computer science, to breaking down a problem into smaller, easier to solve problems is called decomposition.
  • Let's try decomposition on the following not so complex problem:
 Write a program such that when a user inputs a number, the program
will output it is an even or an odd number.
  • To break down the above problem, we are going to use flowchart to help us.
  • Flowcharts are very useful in visualising how algorithms work.

3 Algorithms with Flowchart

Learn It - flowcharts

  • A flowchart is a type of diagram that represents an algorithm, workflow or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows.
  • Each shape represent some steps in the algorithm:

flowChartShapes.png

  • The following is a simple example of using flowchart to describe the steps to a simple problem of determing if an user's input numbers are odd or not.
  • The above problem has been decomposed into three parts:
    1. a user input a number
    2. determine if the number is even or odd
    3. output the appropriate message depending on the above step

Try It

Write a computer game that allows a user to guess the number that is
 picked by a computer. If the user guessed the number, the user is 
declared a winner. If the user guessed incorrectly, the computer will
 tell the user if the guess is too high or two low. 
  • Try your decomposition skill with the above problem.
  • The first few steps have been started for you:
    1. computer pick a number
    2. a user input a number

Badget It - Silver

Learning Strand: Algorithms

  • Finish decomposing the problem by finishing all steps required to reach a solution.
  • Create a flowchart using appropriate symbols for your steps.
  • Upload both your steps and flowchart to www.bournetolearn.com

4 Solving a real life problem with flowchart

Learn It - the light house

  • Launch the application flowol, click on File->New and you should see something like the following:

flowol-1.PNG

  • Select the lighthouse mimic by clicking on it
  • The scenario or mimic has one input:the Sun and three outputs: Lamp, Lights and Foghorn

flowol-lighthouse-1.PNG

Try It

  • flowol is simple to use once you know it
  • See if you can work out how to create a flowchart as shown below:

flowol-lighthouse-2.PNG

  • If you stuck, ask your teacher to show you

Badge It - Gold

Learning Strand: Algorithms

  • The above flowchart will make the three outputs flash on and off every two seconds
  • Your task is to create a flowhcart so that:
    • when the Sun is down(off), all the three outputs will flash
    • when the Sun is up (on), all the outputs should be off.
  • Test your flowchart by clicking on the Sun to turn it on and off.
  • Screenshot your working flowchart and upload to BTL

Badge It - Platinum

Learning Strand: Algorithms

  • Now you are familar with how the software flowol works.
  • The above mimic has all three outputs flash on and off.
  • follow the steps shown in the image below to create a flash function:

flowol-define-function.png

  • Once you have created a function, the side menu will now have Sub block for you to use the functions you have created.

flowol-function.png

  • Modify your flowchart from the Gold badge task to use this function.
  • Test your flowchart as you have done with your Gold badge and upload the screenshot of your working flowchart to BTL.