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

Representing Algorithms

Uploaded by

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

Representing Algorithms

Uploaded by

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

REPRESENTING ALGORITHMS

BOOK PAGES: 10-11 & 98-101


 Computational thinking involves thinking about a problem in a logical way, and enabling a computer to solve
it.
 Logical reasoning is the process or method of using a rational and systematic approach to solve a problem.

It will often be based on mathematical assumptions and procedures


COMPUTABLE PROBLEMS

Not all the problems can be solved by computers. A problem that can be solved by computers has
these features:
 The problem is clearly stated
 The solution is clearly stated
 There are logical steps that can get us from the problem to the solution.
Sometimes it is easy to work out the solution. In other cases, it can be difficult.
HOW CAN WE SOLVE A PROBLEM?
1. ABSTRACTION
The process of taking away or removing characteristics from a problem in order to do it to understand.

Make the London tube map

Without Abstractions With Abstractions


WHY IS ABSTRACTION SO IMPORTANT?
 Ignore inconvenient detail
 Treat different entities as though they are the same
 Simplify many types of analysis
 Is very helpful tool for decomposition

!! ABSTRACTION DOESN’T SOLVE PROBLEMS…

…BUT IT ALLOWS US TO SIMPLIFY THEM


TASK 1

A man called Fred wishes to cross a 10 meter wide river with a wolf, a white goat and a bail of newly cut hay.
He has a small blue boat and oars, but unfortunately he can only take one thing across at a time. The problem
is, if he leaves the wolf and the goat alone together, the wolf will eat the goat, and if he leaves the goat with
the hay, the goat will eat the hay. They are currently all together on one side of the river, which we will call
bank B, and they want to get to the other side, called bank A. How does he do it?
First of all we should find out all the irrelevant details and ignore them. Then we can try to find the solution.
TASK 2 – BOOK (page 101)

1. Abstraction means removing unnecessary details. Explain in your own words how we know which
details are necessary or unnecessary?
2. Explain how abstraction helps with reusability.
3. A programmer was asked to write a program to work out the average weight of apples in an
orchard. What details can she leave out of the algorithm? What details would she include?
2. DECOMPOSITION

Decomposition is when you are breaking a problem into a number of sub-problems, so that each sub-
problem accomplishes an identifiable task, which might itself be further subdivided.

The main purpose of decomposition is to help you find your solution much easier!!
LET’S MAKE A LEMON PIE
Each part of the recipe acts as a Modularity allows the programmer to truckle
separate module! problems in a logical fashion
TIPS FOR A GOOD DECOMPOSITION

 Each subproblem is at (roughly) the same level of detail.

 Each subproblem can be solved independently.

 The solutions to the subproblems can be combined to solve the original problem.
ADVANTAGES OF DECOMPOSITION:

 It saves time
 Reduces complexity
 Increasing reliability as the modules will have already been tested in another program.
 It is easier to update or fix the program by replacing individual modules rather than larger amounts of
code
 Avoids the increased possibility of data corruption often caused by using a large number of lines of code
 Ensures that there is a logical structure in the program being written, which make the code more efficient
and easier to understand and modify.
DISADVANTAGES

 The solutions to the subproblems might not combine to solve the original problem.

 Poorly understood problems are hard to decompose


WHAT IS AN ALGORITHM?
Algorithm is a sequence of steps that can be followed to complete a task and it always runs in finite time.

COMPUTER PROGRAMS ARE USING ALGORITHMS.

BUT

AN ALGORITHM IS NOT A COMPUTER PROGRAM!


CODE NEEDS ALGORITHMS!

 You use code to tell a computer what to do. Before you write code you need an algorithm.
 An algorithm is a list of rules to follow in order to solve a problem.
 Algorithms need to have their steps in the right order. Think about an algorithm for getting dressed
in the morning. What if you put on your coat before your jumper? Your jumper would be on top of
your coat and that would be silly! When you write an algorithm the order of the instructions is very
important.
HOW DO YOU USE ALGORITHMS?
People use lots of algorithms every day even if they don’t realise it. Choose from three problems and guess
what the algorithm might be!

We need to build
We need to make We can’t find the
a toy!
a cake! park!

The algorithm here is a The algorithm you need is a


The algorithm to follow
cake recipe. You can find set of directions to get to the
here is the list of
the algorithm to solve park! There might be different
instructions that tell you
this problem in a ways to the park so you can
how to make the toy.
cookbook! have different algorithms.
SOME APPLICATIONS OF ALGORITHMS:

• GOOGLE SEARCH ENGINE


• FACEBOOK’S NEWS FEED
• GOOGLE MAPS
• EXCEL
• WEATHER FORECAST
• "YOU MAY ALSO ENJOY...": (AT AMAZON, NETFLIX,…
• HIGH FREQUENCY STOCK TRADING
WHY DO PROGRAMMERS WRITE ALGORITHMS?
Why do programmers spend time writing algorithms? Why don’t they just start writing program
code? There are several reasons. Setting out the solution in the form of an algorithm helps
programmers to:
 Plan their solution and check that it makes sense before they begin writing code
 Share their solution with other programmers, including people who use a different
programming language
 Keep a record of their solution. There are lots of different programming languages. A
programmer can read an algorithm and turn it into code in any language. A good algorithm
can be used by many different programmers.
TASK 2 - CLEAR INSTRUCTIONS
When you write an algorithm you need to include
precise, step-by-step instructions.
Task: can you put the following instructions in order for
making a smoothie:

Step
Add milk to the
Imagine if we missed out one of the steps or
1 blender
Step
reversed the order. We could end up switching on Put the lid on the
the blender with nothing in it. Or there could just 2 blender
be milk in the blender and no fruit. Step
Switch the blender
That wouldn't make a very tasty smoothie, would
it? In fact, it wouldn't make a smoothie at all! 3 on
Step
Add fruit to the
4 blender
TASK 3 – BOOK (page 99)

1. An algorithm can include calculations. What operators do we use to express calculations?


2. An algorithm can include logical tests. What operators do we use in logical tests?
3. What is the difference between an algorithm and a computer program?
TASK 4

Write an algorithm that adds 2 number. The number should be inputted by the user
SEQUENCE
 Sequence is a set of steps taken in order, one thing following after another.

Your commands should have the correct order otherwise your program will not be able to run.
For example:
1. INPUT first number
2. ADD first and second number together
This will not
3. INPUT second number run…
4. STORE as total
5. OUTPUT total
ASSIGNMENT & VARIABLE
Assignment is when you are saving an input with a name (in this instance: first number, second number)

We can set and/or re-set the value stored in a storage location. For example: the first number could be 5 and
the second number could be 6.
If we re-run the algorithm we could re-set the first number to be number 8 and the second number could be 2.
The program will run again and find the new solution.

 Variable is a value that can be changed.


TASK 5 – BOOK (page 11)

What is an algorithm? Why do programmers create algorithms before they start to write program
code?
KEY WORDS
 Abstraction is the process of removing unnecessary details from a problem to make it easier to solve it.
 Decomposition is the process of breaking a problem into a number of sub-problems, so that each sub-problem
accomplishes an identifiable task, which might itself be further subdivided.
 Algorithm is a sequence of steps that can be followed to complete a task and always terminates (runs in finite
time).
 Sequence is a set of steps taken in order, one thing following after another.

You might also like