Algorithmic Thinking and Problem Solving.Test 1docx
Algorithmic Thinking and Problem Solving.Test 1docx
Algorithmic Thinking
A problem is a task to be performed. Asking some basic questions about a problem can help
define the problem. Some pertinent questions to ask are:
Imp
A problem is understood and solved using available facts or data. This data is, entered in the
algorithm as input which is processed into an outcome, called the output. A problem therefore,
consists of inputs and matching outputs.
Let's define and state a real-life problem, using the above method.
Suppose your classmate is arriving late to school everyday, due to which he/she is having
difficulties in understanding the lessons. He/she has also received warning from the
headmistress. You can ask questions from your friend to understand the problem. Some
questions and their possible responses are given on the table.
66
Imp
Responses
Questions
Sleeping early
yfiend has a problem of arriving late to school, due to which he/she is facing learning fficulties
Problem statement: "My friend Arsalan, who is my classmate, needs to have a proper cutine to
sleep early because he is facing learning difficulties due to his habit of sleeping re at night and
getting up late in the morning.
Top Tip
Think of a problem you or your friends face and frame a problem statement. You could use the
flowing template:
(Pactice)
Sajida (user) is a/an Filend wake earl early (user's needs) because (user characteristics who
needs to she is La thinsightly
impie problems can be solved using a straightforward algorithm. Recipes and sorting jects are
examples of simple problems. However(creating an online map is a complex problem because
numerous factors will have to be considered, such as traffic situation, th hours, road blockages,
etc. Similarly, facial recognition is a complex problem because dependent on several underlying
factors such as light, changes in the expression of Deface, etc. Computational thinking is great
approach for solving all types of problems.
Making a sandwich
SKFORD
67
4 Algorithmic Thinking
22 Jan, Monday
CT is essentially a framework to describe a set of critical thinking and problem- solving skill CT
may be considered a precursor to learning actual coding or computer programming skills.
Representing data through abstractions which means removing unnecessary details to simplify
the process.
• Identifying, analyzing, and implementing possible solutions with the goal of achieving the most
efficient and effective combination of steps and resources.
Computational thinking enables people to create technology, rather than just consuming
technology. It gives them the confidence and the persistence in working with difficult
problems. readandwite/Learm
Algorithm A
An algorithm is a precise, step-by step process to solve a problem. A problem can be solved by
using different algorithms.
By definition, something can only be called an algorithm, if it has all of the following properties.
1. It must be correct. In other words, it must compute the desired function, converting each input
to the correct output.
Neil earning
2. It is composed of a series of concrete steps. Concrete means that the action described by
that step is completely understood and doable by the person or machine that must perform the
algorithm. For example, the steps of a cookie recipe in a cookbook might be considered
sufficiently concrete for instructing a human cook, but cannot be used for programming an
automated cookie-making factory.
68
next. The instructions hould be specific because non-specific instructions are vague and will not
help in difying the next steps. Selection (e.g. the 'if statement') is normally a part of any Inquage
for describing algorithms. Selection allows a choice for which step will be performed next.
must be composed of a finite number of steps. Most languages for describing arithms including
English and "pseudocode") provide some way to perform epeated actions, known as iteration.
Examples of iteration in programming languages clude the while loop' and 'for loop' constructs.
Iteration allows for short descriptions, with the number of steps actually performed controlled by
the input. must terminate. In other words, it may not go into an infinite loop.
What is an Algorithm?
Algorithm
Input
Output
Algorithmic thinking
panithmic thinking is a systematic way of thinking through problems and finding nitions in a way
similar to how a computer would solve a problem. comprises of the following steps:
moller, manageable parts. There are different techniques to deconstruct a problem. A limple
problem could be subdivided into smaller parts that do not need to be further hdivided.
However, complex problems are first deconstructed into broader groups and then sub divided
into further smaller parts to understand the problem. Pattern Recognition: This pertains to
observing patterns, trends, and regularities in
data. Similar patterns could be classified together. Abstraction: patterns could be close
understandable by reducing unnecessary detall Algorithm Design: Developing the step-by-step
instructions for solving a certain
problem and simitar problems. Evaluation: Ensuring that your solution is efficient.
FORD
69
ondy 2a Jan24
Algorithmic Thinking
The advantage of developing more than one solution to a problem is that there would be
multiple ways to solve a problem and to select the best solution,
Solution A might be more efficient than Solution B for a specific variation of the problem, or for a
specific class of inputs to the problem, while solution B might be more efficient than A for
another variation or class of inputs.
An algorithm might work for sorting a small collection of integers (which is important if you need
to do this many times); while another algorithm might work for sorting a large collection of
integers. A third might be the best for sorting a collection of variable-length strings
Designing an algorithm
(whole)
Computers rely heavily on algorithms to do useful work. Computers can neither function with
Intuitive knowledge, nor do they have their own intelligence to make decisions. They depend on
humans to provide them with the "thought pattern" or the "method" of doing work.
An algorithm should contain all the necessary inputs, outputs, instructions, decisions, etc. to
solve the problem. When designing an algorithm, consider more than one way of solving the
problem. The following aspects should be taken into account.
⚫ the individual stages - What hurdles need to be overcome on the way to the goal?
1. Algorithms are a set of rules and by following these rules, one can solve a problem.
Algorithmic thinking is the best approach to solve a problem. One can decompose complicated
problems into smaller components and work on them one at a time.
4. In algorithmic thinking process, one must analyse trends and patterns, which helps to develop
analytical thinking skills. 5. Algorithmic thinking enables us to arrive at different solutions to the
same problems.
70
here w
The problems
which helps
OXFORD
artingolay
Let's make a Pizza
For solving a problem, the steps are to be written down in the order they will be followed.
ther fuci Following a recipe is an example of solving a simple problem. If you are asked to make
a pizza, some questions to be asked could be: What ingredients would be required?
ions. Tivi
doing wast
decitinge
way of w
the goa
(The process of writing an algorithm starts by breaking down the problem step-by-step.
Add mushroom
Google: Google search engine uses an algorithm, PageRank, to determine which search results
appear and in what order, ensuring the highest-quality, most credible websites appear first. This
algorithm is run every time a query is s s searched.
whole Page
YouTube: YouTube uses recommendation algorithm based on the users search history.
tomata paste
Fig.4.5
71
4 Algorithmic Thinking
Computers work in the same way too. The complete process starts from identifying a problem
and ends with finding a solution using an algorithm. We can implement the algorithmic thinking
in our daily life by analyzing the problems we
Making Tea
The step-by-step process of making tea is shown below. This is an example of a simple
problem.
Think about your daily morning routine. Your actions are usually in a sequence.
Step 1: Get up
Solving a sum
Step 2: Press 2
Step 3: Press'+'Sign
Step 4: Press 3
Step 5: output 5
72
Consider examples 1 till 4. To solve the problem, you need to identify the ingredients and
methods, think logically how to sequence the steps and test if the desired outcome is achieved.
The evaluation of steps can either lead to confirmation or revisiting the algorithm to improve the
steps. This process will give you confidence in decision making.
Conditional statements
Selection is a question or a decision. It allows us to find more than one path through on
algorithm. This is where If else condition is used. If the water boils, add tea leaves else wait.
Let's look into our tea making process. In step 4 we have to wait for water to boil but we haven't
disclosed any time for boiling because we are not aware of depending factors like gas pressure
or the type of pan we are using. So what we will do in this case, we will wait until water boils.
Move to step 5
Top Tip
Else Wait
There is one condition in this algorithm that if water boils we will proceed to the next step else
we will continue the waiting process.
Logic tells us that either a rule needs to be added, or the existing rules need to be changed.
Logical operators
We can use AND, OR, NOT logical operators as well for making our condition more powerful
which helps us in filtering conditions more effectively.
Move to step 5
Else Wait
OXFORD
Let's use these logical operator with logical reasoning. IF Water Boils then
Condition/Selection
This is a decision within a computer program when the program decides to move, based on the
results of an event.
73
Algorithmic Thinking
Loops
Number 2:
logical operators
Number 1
Loops are a fundamentol concept in algorithms, as they allow for efficient repetition ofa set of
instructions. Repetitive tasks are common in programming, and loops are essential to save time
and ensinimize errors. Loops in Scratch are of two types.
74
So you can see in above example that there are 2 different points where we can use
Now you can see that we have used sign which is an equal operator
Example
Relational Operators
Operator Symbol
Operator Name
Equal to
Greater Than
Less Than or
Ergual To
Equal To
Not Equal Te
Javatpoint
A
A Fig 47 showing logen per for algorithms
Description
Tests whether the star is greater than certain value or Testy whether the volce is less than
certain value or not Sets whether the value is greater than or equal to certain value or not
Tets whether the value in less than or equal certain velur of nat
Finite Loop
Infinite Loop
Sequence
The sequence shows the order in which the steps are to be taken. If the order is not followed,
the desired outcome will not be achieved. Consider the example of moming routine of a student.
The student follows a certain sequence every morning.
Selection
Repetition
Exercises
OXFORD
biond
75
1. Choose the correct option. (Tick all that apply.) a. What should be considered when designing
an algorithm?
In Repetition, the algorithm repeats a certain step till a certain condition is met. For example, if
you enter a wrong password to log in to your email account, you will get o prompt to try again. If
you enter a wrong password again, the same prompt would be repeated. For security reasons,
there is a limit to the number of times to enter a password
In Selection, different sets of steps can be selected. Consider the example of making tea. If the
Water boils is an example of selection.
An algorithm is made of three separate building blocks: Sequence, Selection, and Repetition.
Infinite loop also called as forever loop, allows the code (steps/instructions) to run for infinite
number of times. A music playlist on repeat mode is an example of an infinite loop. Traffic lights
are another example of infinite loop because they work round the clock to control the traffic flow.
Fierite loop also called as repeat loop, allows the steps/instructions to run for a particulor
number of times. A playlist that normally ends after the last song is an example of a finite loop