Learn Algorithms and Decomposition
Learn Algorithms and Decomposition
being
recorded
APPLY TASK ANSWER
WEEK 1
Starter
What is an Algorithm?
What is an Algorithm?
For example, imagine you have a bag of coloured blocks, and you want to find a specific block, let’s say a
blue block, in the bag. Here’s a simple algorithm you can follow:
Computers are really good at following algorithms, even much more complex ones. They can solve
problems much faster than humans because they can follow instructions very quickly.
Algorithm – Baking a cake example
Below is a simple algorithm for baking a cake, but the steps are in the wrong sequence.
Could you number the steps in the correct sequence so that the algorithm will run as expected?
Below is a simple algorithm for baking a cake, but the steps are in the wrong sequence.
Do you agree that this is the correct sequence so that the algorithm will run as expected?
Computers require algorithms to function and these usually come in the form of software.
Computers differ from humans in that the instructions provided must completely unambiguous – they must
be clear and not open to interpretation .
Computer Algorithms used in computers are usually written in text or block based programming languages
such as Python or Scratch, though some algorithms are physically wired into a computer.
How Algorithms can be represented
Written Program Descriptions
A written description is a narrative explanation of the program’s logic using natural language or structured English.
It focuses on conveying the overall flow and behaviour of the program without diving into the details of individual steps. It is more
suitable for high-level understanding and communication between stakeholders, such as clients, project managers, or non-
technical team members.
Written descriptions may lack the precise syntax and structure found in pseudocode or programming languages.
Example
From the above the developer should be able to ( perhaps after asking some additional clarification questions)
code the program described.
How Algorithms can be represented
Pros:
Accessibility: Written descriptions can be easily understood by non-technical individuals.
Flexibility: They can be written in plain language or tailored to the target audience, allowing for customization and adaptation to
different contexts.
Clarity: They focus on the program’s purpose, requirements, and expected outcomes, enabling stakeholders to grasp the essence of
the program without getting bogged down in technical details.
Cons :
Ambiguity: Written descriptions may be prone to misinterpretation due to the use of natural language.
Lack of Detail: They may not capture the specific steps or decision-making processes involved, making it challenging to translate
them directly into code.
Difficulty in Validation: Unlike pseudocode or actual code, written descriptions are not easily testable.
Limited Reusability: Written descriptions are not directly executable and cannot be reused as code snippets. They serve more as
documentation or communication tools rather than practical implementation instructions.
How Algorithms can be represented
Pseudocode
Pseudocode is a way of representing a program’s logic using plain language. It helps in understanding the algorithm without getting
into the specifics of any particular programming language.
1. Start
2. Declare variables num1, num2, sum
3. Read num1 from the user
4. Read num2 from the user
5. Set sum = num1 + num2
6. Display "The sum of", num1, "and", num2, "is", sum
7. Stop
Pseudocode aims to strike a balance between human-readable natural language and structured programming constructs. It helps
programmers communicate and understand the algorithm’s flow and logic, making it easier to translate into actual code in a specific
programming language.
This program code is easy to read but can easily be converted into fully working code by a developer. As pseudocode isn’t a real
language there is not official set way to write it, since pseudocode need only be logically correct, no syntactically correct.
How Algorithms can be represented
Edexcel iGCSE Pseudocode
All exam boards here their own versions of pseudocode. It is important to note that while you don’t strictly need to follow this list
exactly when writing pseudocode in the exam, it is highly recommended as otherwise you risk losing marks in the exam.
You saw a copy of this in your first lesson.
Pros :
Readable and understandable by both technical and non-technical individuals.
Provides a clear and structured representation of program logic.
Language-agnostic, allowing for flexibility and adaptability to different programming languages.
Facilitates validation and testing of program logic before implementation.
Cons :
Subjective and open to interpretation.
Lack of standardization in syntax and format.
May lack implementation-specific details.
Not executable code, requiring translation into an actual programming language.
How Algorithms can be represented
Flowcharts
Example
Cons :
Complexity: Code can be complex, especially for large and intricate programs, which can make it harder to understand and
maintain.
Technical Knowledge Requirement : Understanding and working with code generally requires knowledge of programming
languages.
Limited Accessibility: Program code may be less understandable for individuals who are not familiar with programming concepts
Less Flexibility: Code is tied to specific programming .
Lack of Abstraction: Code is less suitable for communicating concepts to non-technical individuals.
Decomposition
In order to create an algorithm or solve a problem, one of the first steps you should do is to break the
problem down into smaller parts.
Once a problem has been broken down and the sub-problems have been identified, algorithms can be
developed to solve each of them.
Decomposition of a problem into sub-problems
Decomposition means that sub-problems can be worked on by different teams at the same time.
As smaller algorithms are developed for each sub-problem, it is easier to spot and correct errors.
When the algorithm is developed into a program, code can be used again.
Plenary
Use the following summary and video link to make notes for your Apply task.
https://www.youtube.com/watch?v=DBRNE3A5Wvw&list=PL04uZ7242_M5F0O5YicE_oxG0e2rvWq-q&index=22
Syllabus
APPLY TASK
Check your ‘to do’ list
for your Apply task
Deadline 1 week
Lesson complete!
See you next lesson