0% found this document useful (0 votes)
12 views

Program Decomposition

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Program Decomposition

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DECOMPOSITION

Decomposition in computational thinking is the process of breaking down a


problem into several smaller problems that can more easily be addressed.

Example: Solving a crime using decomposition


It is only normally when we are asked to do a new or more complex task that we
start to think about it in detail – to decompose the task.
Imagine that a crime has been committed. Solving a crime can be a very complex
problem as there are many things to consider.
For example, a police officer would need to know the answer to a series of
smaller problems:

 what crime was committed


 when the crime was committed
 where the crime was committed
 what evidence there is
 if there were any witnesses
 if there have recently been any similar crimes

The complex problem of the committed crime has now been broken down into
simpler problems that can be examined individually, in detail.
There are different methods used to design and construct a solution to a problem.
These include flowcharts, structure diagrams and pseudocodes.

FLOWCHARTS
Designing effective problem-solving flowcharts involves careful consideration of
various factors to ensure clarity, accuracy and usability. Here are some best
practices to create efficient and useful problem-solving flowcharts:

 Understand the problem first & clearly define it


 Keep it simple
 Use standard & recognizable symbols
 Ensure that the flowchart follows a logical and sequential order
 Clearly label each decision point, action, and outcome
 Verify the flowchart’s accuracy by testing it
 Clearly state the decision criteria that lead to different branches
 Provide context when the flowchart is part of a larger process or system
 Review and revise the flowchart

Steps of problem-solving using flowcharts?


1. Define the Problem
Before anything else, it’s essential to articulate the problem or task you want to
solve clearly and accurately. By understanding exactly what needs to be
addressed you can ensure that subsequent steps align with the core issue.

2. Identify the Inputs and Outputs


Determine what inputs (such as data, information or resources) will be required
to solve the problem and what the desired outputs or outcomes are. Identifying
these factors will guide you in structuring the steps needed to reach the end goal
and ensure that all necessary resources are at hand.

3. Identify the Main Steps


Break down the problem-solving process into its main steps or subtasks. This
involves pinpointing the essential actions or stages necessary to reach the
solution. Create a roadmap that helps in understanding how to approach the
problem methodically.
4. Use Decision Symbols
In problem-solving, decisions often lead to different paths or outcomes. Using
standard symbols to represent these decision points in the flowcharts allows for a
clear understanding of these critical junctures. It helps visually present various
scenarios and their consequences.

5. Add Descriptions and Details


A well-designed flowchart is concise but clear in its labeling. Using arrows and
short, descriptive phrases to explain what happens at each step or decision point
ensures that the flowcharts communicate the process without unnecessary
complexity.

6. Revise and Refine


Creating a flowchart is not always a one-and-done process. It may require
revisions to improve its clarity, accuracy, or comprehensiveness. Necessary
refinement ensures that the flowcharts precisely reflect the problem-solving
process and are free from errors or ambiguities.

PSEUDO-CODE
This is a term which is often used in programming and algorithm-based fields. It
is a methodology that allows the programmer to represent the implementation
of an algorithm. Pseudocode literally means ‘fake code’. It is
an informal and contrived way of writing programs in which you represent the
sequence of actions and instructions (aka algorithms) in a way that humans can
easily understand.
The language of a computer is very rigid: you are not allowed to make any
mistakes or deviate from the rules, making it hard for an average human
developer to reason and create a program code. With pseudocode, however, it’s
the exact opposite. You make the rules. It doesn’t matter what language you use
to write your pseudocode. All that matters is comprehension.

In pseudocode, you don't have to think about semi-colons, curly braces, the
syntax for arrow functions, how to define promises, DOM methods and other core
language principles. You just have to be able to explain what you're thinking and
doing.
Advantages of Pseudocode
 Improves the readability of any approach – it is one of the best approaches to
start implementation of an algorithm.
 Acts as a bridge between the program and the algorithm or flowchart. Also
works as a rough documentation, so the program of one developer can be
understood easily when a pseudo code is written out. In industries, the
approach of documentation is essential. And that’s where a pseudo-code
proves vital.
 The main goal of a pseudo-code is to explain what exactly each line of a
program should do, hence making the code construction phase easier for the
programmer.

How to Solve Programming Problems with Pseudocode


Solving programming problems can be hard. Not only do you have the logical part
to reckon with, but also the technical (code creating) part as well.

Here are the steps you can follow to solving programming problems with
pseudocode:

Step 1: Understand what the function does


First, you need to understand that all a function does is (optionally) accept data as
input, work on the data little by little, and finally return an output. The body of
the function is what actually solves the problem and it does so line by line.

Step 2: Make sure you understand the question


Next, you need to read and understand the question properly. This is arguably the
most important step in the process.

If you fail to properly understand the question, you won’t be able to work through
the problem and figure out the possible steps to take. Once you identify the main
problem to be solved you'll be ready to tackle it.

Step 3: Break the problem down.


Now you need to break down the problem into smaller parts and sub-problems.
With each smaller problem you solve, you'll get closer to solving the main
problem.

It helps to represent these problem-solving steps in the clearest and most easily
understandable way you can – which is pseudo-code!

How to write a Pseudo-code?


1. Arrange the sequence of tasks and write the pseudocode
accordingly.
2. Start with the statement of a pseudo code which establishes
the main goal or the aim. Example:
This program will allow the user to check
the number whether it's even or odd.

1. The way the if-else, for, while loops are indented in a


program, indent the statements likewise, as it helps to
comprehend the decision control and execution mechanism.
They also improve the readability to a great extent.
Example:
if "1"
print response
"I am case 1"
if "2"
print response
"I am case 2"

1. Use appropriate naming conventions. The human tendency


follows the approach to follow what we see. If a programmer
goes through a pseudo code, his approach will be the same as
per it, so the naming must be simple and distinct.
2. Use appropriate sentence casings, such as CamelCase for
methods, upper case for constants and lower case for
variables.
3. Elaborate everything which is going to happen in the actual
code. Don’t make the pseudo code abstract.
4. Use standard programming structures such as ‘if-then’, ‘for’,
‘while’, ‘cases’ the way we use it in programming.
5. Check whether all the sections of a pseudo code are
complete, finite, and clear to understand and comprehend.
6. Don’t write the pseudo-code in a complete programmatic
manner. It is necessary to be simple to understand even for a
layman or client, hence don’t incorporate too many technical
terms.

Let’s have a look at this code


def gcd(numberOne, numberTwo):
if numberTwo == 0:
return numberOne
return gcd(numberTwo, numberOne % numberTwo)

def lcmNaive(numberOne, numberTwo):


lowestCommonMutliple = (numberOne * numberTwo) / gcd(numberOne,
numberTwo)
return lowestCommonMutliple

numberOne = 5
numberTwo = 2

print(lcmNaive(numberOne, numberTwo))

You might also like