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

Learn Algorithms and Decomposition

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

Learn Algorithms and Decomposition

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

This lesson is

being
recorded
APPLY TASK ANSWER
WEEK 1
Starter

What is an Algorithm?

Theory Past Paper Mark Scheme Video


Starter

What is an Algorithm?

An algorithm is a set of unambiguous, step-


by-step instructions used to solve a
problem. They are used by both human
beings and computers.

Theory Past Paper Mark Scheme Video


Edexcel iGCSE Computer
Science

1.1.1 Understand & use algorithms


1.2.2 Decomposition and sub-problems
Syllabus
Learning Objectives

Understand what an algorithm is

Understand what decomposition is

Be able to decompose large problems into smaller sub-problems


Textbook Reference

Although there are lots of resources available for this


qualification, your lessons refer to this textbook.
Pearson Edexcel International GCSE (9-1)
Computer Science Student Book
1.1.1 pages 12 - 19
1.2.2 pages 31 - 36
Algorithms
Put simply, it is a set of instructions to perform a specific task . Almost any task can be described with 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:

1. Take out one block from the bag.


2. Check if the block is blue.
3. If it is blue, you found the block! Yay! Stop searching.
4. If it’s not blue, put the block aside and go back to step 1.
5. Repeat steps 1-4 until you find the blue block.
In this example, the algorithm is a series of steps that helps you find the blue block. You repeat the steps
until you find what you’re looking for.

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?

Fold in flour until completely mixed


Sift flour into creamed butter and sugar
Cream butter and sugar
Line baking tin
Pre-heat oven
Bake until golden brown
Weigh ingredients
Leave to cool
Pour batter into lined tin
Algorithm – Baking a cake

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?

Fold in flour until completely mixed 6


Sift flour into creamed butter and sugar 5
Cream butter and sugar 4
Line baking tin 2
Pre-heat oven 1
Bake until golden brown 8
Weigh ingredients 3
Leave to cool 9
Pour batter into lined tin 7
Algorithms for Computers

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

"The program prompts the user to enter two numbers.


It then calculates the sum of the two numbers and
displays the result on the screen."

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.

Example – program to add two numbers

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

 A flowchart is like a visual map that helps you


understand and follow a process or make decisions step
by step.
 It uses different shapes and arrows to show the order
of actions or choices you need to take.
 Each shape in a flowchart represents a different action
or decision, and the arrows show you the direction to
move in.
 You start at the beginning and follow the arrows until
you reach the end.
 It’s like having a visual guide that helps you stay
organized and make better choices.
How Algorithms can be represented
Program Code
Program code is code that can be directly executable (or with a few minor changes) in the target language.

Example

# Read input from the user


num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

# Calculate the sum


sum = num1 + num2

# Display the result


print("The sum of", num1, "and", num2, "is", sum)
How Algorithms can be represented
Pros :
 Precision and Execution: Program code provides precise instructions that can be directly executed by a computer.
 Implementation-Ready : Program code is the actual implementation of the logic, making it ready for use.
 Verifiability: Program code can be tested and validated to ensure that it produces the desired results.
 Reusability: Code can be reused in other projects or parts of the same project, saving development time and effort.
 Efficiency: Program code is optimized for performance and can be fine-tuned to achieve optimal speed and resource usage.

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.

This is called decomposition.

Decomposition is usually the first step in the problem-solving process.

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

You might also like