0% found this document useful (0 votes)
37 views43 pages

4.1 Thinking Procedurally

Uploaded by

Sahaj Khurana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views43 pages

4.1 Thinking Procedurally

Uploaded by

Sahaj Khurana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Unit 4: Computational

Thinking
Concept of a problem
Concept of a problem
• According to the Cambridge Dictionary: “ A problem is a situation that
needs attention and needs to be dealt with or solved.” Whenever we
have to deal with a problem we have to take one or more decisions.
• Herbert A. Simon was a pioneer in many fields including decision
making. He originally defined 3 steps in decision-making that is
intelligence gathering design and choice other researchers refined
these 3 stages as a sequence of identification development and
selection in both the cases and implementation phase follows.
Concept of a problem(Continued)
• Every time you need to solve a problem you have to take a decision
according to these steps. Sometimes a person finding a solution to a
problem must return to a previous phase and improve the outcome
before proceeding to the next phase.
• Imagine a situation where during a selection phase the chosen
alternative does not return the desired results in an efficient way.
• It is then necessary to return to a development phase and explorer
again various alternatives.
Concept of a problem(Continued)
• Identify the problem
Identification • Understand the problem
• Formulate the problem

Development • Explore various alternatives

Selection • Choose the best alternative

Implementation • Implement the selected solution


What is an Algorithm?
• An algorithm is a step-by-step procedure or set of rules
used to solve a specific problem or accomplish a
particular task.
• In computer science and mathematics, algorithms play
a fundamental role in problem-solving and data
processing.
• They are like recipes or instructions that guide a
computer or a person through a series of well-defined
steps to achieve a desired outcome.
Algorithm
Efficient Algorithm must possess the
following properties:
• Finiteness: “An algorithm must always terminate after a finite number of
steps.
• Definiteness: “Each step of the algorithm, must be precisely defined; The
actions to be carried out must be rigorously and ambiguously specified for
each case.
• Input: “… quantities which are given to it initially before the algorithm
begins. These inputs are taken from specified sets of objects”
• Output: “… quantities which have a specified relation to the inputs.”
• Effectiveness: “…all of the operations to be performed in an algorithm must
be sufficiently basic that they can in principle be done exactly and in a finite
length of time by a man using paper and pencil.”
Write an Algorithm as a recipe to
boil an egg
• Start within an egg at room temperature.
• Bring a small pan of water to boil.
• Put the egg in the pan.
• Boil for 4 minutes.
Different Algorithm will have
different
expressions(implementations):
Algorithm may be expressed in a
number of ways:
• Simple English(natural Language)
• By flowchart
• Pseudocode
• Programming language
Flowcharts:
• A flowchart is used to diagrammatically describe an algorithm using
different shapes and arrow lines to describe the flow of the program.
Pseudocode
• Pseudocode is a high-level, informal, and human-readable
description of an algorithm or a computer program.
• It is not tied to any specific programming language and does
not use strict syntax like actual code. Instead, pseudocode
uses natural language and simple constructs to outline the
logic and steps of the algorithm or program.
• Pseudocode acts as a blueprint or outline for implementing an
algorithm in a specific programming language. Once the logic
is well-defined in pseudocode, developers can then convert it
into the syntax of their chosen programming language, making
the actual coding process more straightforward and less error-
prone.
Pseudocode Characteristics:
1.Language Agnostic: Pseudocode is not bound to any particular
programming language. It uses general English-like statements, making it
accessible to developers with different programming backgrounds.
2.Readable and Understandable: Pseudocode is designed to be easy to
read and comprehend. It aims to communicate the algorithm's logic clearly,
without getting bogged down in syntax details.
3.Simple Constructs: Pseudocode typically employs simple constructs and
plain language to represent common programming elements like loops,
conditionals, and variables.
4.Step-by-Step Logic: Pseudocode breaks down the algorithm into a series
of steps, explaining the flow of execution and decision-making processes.
5.No Specific Implementation Details: Pseudocode does not include
specific implementation details like data types, function definitions, or
specific syntax rules found in programming languages.
Pseudocode Example
Set sum to 0
Set N to the desired number of natural numbers
For each number from 1 to N:
Add the number to the sum
End For
Print the sum
Algorithm vs Pseudocode
• An algorithm is a formal, logical, and specific set of
rules to solve a problem, while pseudocode is an
informal, human-readable representation of an
algorithm's logic, expressed in a language-agnostic
manner and intended to help developers plan and
understand the algorithm before implementation.
Pseudocode acts as a bridge between the algorithm and
the actual code, facilitating a smoother transition from
design to implementation.
Thinking procedurally
4.1.1 Identify the procedure appropriate to solving a problem
4.1.2 Evaluate whether the order in which activities are undertaken will result in the
required outcome.
4.1.3 Explain the role of sub-procedures in solving a problem.
4.1.1 Procedure appropriate to
solving a problem
• To solve a problem effective method or procedure should be
identified.
• This procedure reduces the solution to a series of simple steps.
• These steps have to be followed in the correct order to obtain the
desired output.
• For example, it is impossible to ride a motorcycle if you don't know
how to ride a bicycle so first you have to learn to ride the bicycle and
then you will be able to write the motorcycle.
Write an algorithm to calculate
average of 3 numbers.
• Step 1: Ask user to enter 1st number
• Step 2: Ask user to enter 2nd number
• Step 3: Ask user to enter 3rd number
• Step 4: Add the 3 numbers entered by the user
• Step 4: Divide the sum by 3
• Step 5: Print the Average
4.1.2 Order of activities and
required outcome
• In procedural thinking, understanding the required outcome
is essential because it guides the entire thought process.
Once you know what you want to achieve, you can break
down the task into logical steps and determine the
appropriate order of activities to reach that outcome.
• For example, a company wishes to develop a new
information system. The analysis phase will be the one that
the company should complete before proceeding to the next
stages of the project. If the company tries to implement the
new system without first analysing the problem domain,
then it will lead to a total waste of money, effort and
resources.
4.1.3 The role of sub- procedures in
solving a problem
• Sub-procedures play a vital role in problem-solving and
programming by breaking down complex tasks into
smaller, reusable, and more manageable components.
They improve code modularity, reusability, readability,
and maintainability, making it easier for developers to
create efficient and effective solutions to problems.
• A good approach for confronting a complex problem is to
develop a method of breaking up the problem into smaller
sub-problems this method is very effective and efficient
because it is much easier to attack and the number of sub
problems instead of a big complex problem.
Thinking logically
4.1.4 Identify when decision-making is required in a specified situation.
4.1.5 Identify the decisions required for the solution to a specified problem.
4.1.6 Identify the condition associated with a given decision in a specified problem.
4.1.7 Explain the relationship between the decisions and conditions of a system.
4.1.8 Deduce logical rules for real-world situations.
4.1.4 Decision- making in a
specified situation
• Some problems don’t require any decision to be taken. For example,
adding two numbers.
• Some problems require the use of decisions. For example, traffic
lights.
IB approved Pseudocode List
• Pseudocode Notation
4.1.5 Decisions
required for the
solution to a specified
problem
• In everyday life people are
constantly identifying the
necessary decisions and the
different actions that are
relevant to a problem or a
situation. It is clear that we
take different actions
according, to the prevailing
conditions.
4.1.6 Iteration associated with a
given decision in a specified
problem
• Iteration is the process of repeating a series of instructions. It is
extremely useful in programming and is used to repeat a statement or
a block of statements within an algorithm.
• Iteration is expressed using the "from to loop” and the ”while loop”
statements.
• The IBO approved notation for developing pseudocode includes the
following flowcharts and pseudocode to represent these statements.
• The diamond shape performs a Boolean test, evaluates an expression
and returns a Boolean value (true or false).
From to Loop flowchart example
From to Loop programming example
4.1.7 Decisions and conditional
statements
• A conditional statement performs different instructions depending on
a Boolean test.
• When an If is used In an algorithm a Boolean condition is evaluated
(X>0, X=Y etc.).
• If the condition is true, the (Consequent) statement or statements will
be executed. Otherwise, the execution continues to the (Alternative)
statement or statements. If there is no else branch, the algorithm
continues after the end if.
IF - THEN- ELSE examples
4.1.8 Logical rules for real-world
• Logical rules or rules of inference are obvious rules to most humans.
Programming and algorithmic thinking involves the translation of
these rules into algorithms.
• If we successfully combine the logic with scientific knowledge, we can
easily solve real world computational problems.
4.1.9- identify the inputs and
outputs required in a solution
• Input is something that put into a program while output is something
that is produced by the grogram after a process.
4.2 Connecting
computational thinking
and program design
4.2.3
Algorithm
to solve a
specific
problem
4.2.4
Analyse an
algorithm
presented
as a flow
chart
4.2.5
Analyse an
algorithm
presented as
pseudocode
4.2.6 Construct pseudocode
to represent an algorithm
4.2.7 Suggest suitable algorithms to
solve a specific problem
• Efficiency of an algorithm refers to the amount of the computer resources
required to perform its functions. Minimizing the use of various resources
such as the CPU and computer’s memory is very important.
• Correctness of an algorithm refers to the extent to which the algorithm
satisfies its specification, is free from faults, and fulfils all objectives set
during the design and implementation phase.
• Reliability refers to the capability of the algorithm to maintain a predefined
level of performance and perform all required functions under stated
conditions, having a long mean time between failures.
• Flexibility of an algorithm refers to the effort required to modify the
algorithm for other purposes than those for which it was initially developed.
4.2.9- Determine the number of
times a step in an algorithm will
be performed for given input data

Q. How many times will the ”we” done” message appear if the user
enters 3:20 and b=2?
Ans: Two times

Q. What is going to be the output of the program if the user enters


a=20 and b=2?
Ans: Well Done
Well Done
Well Done
4.3.6- Define the terms: variable,
constant
• Variable: A variable is like a container in a program that holds
information. This information can be changed while the program is
running. Each variable has a special name and a type that says what
kind of information it can hold, like numbers or words.
• Constant: A constant is like a fixed value in a program
that never changes. It's kind of like a special container
that can't be changed once it's set. For example, in a
program, if you set a constant like “PI= 3.14159" the
value of PI will always stay the same and can't be
changed while the program is running.
4.3.6- Define the terms: Operator,
Object
• Operator: Operators help us do math, compare things, and make decisions in our
programs. Operators can do different jobs like adding or comparing
these things. Operands can be variables, literals, boolean values, numerical
values, text etc. Operators can be arithmetic, relational, logical etc.
• Object: An object is like a thing that has information and things it
can do. These things it can do are like tasks it can perform. The
information in an object can be different parts, like numbers or
words. The tasks an object can do are called actions, which might
be things like counting or showing information. The parts that
hold information are called data members, and the actions it can
do are like special methods. So, an object is like a package that
holds stuff and knows how to do certain tasks with that stuff.
4.3.7 define
the
operators
=, ≠, <,
<=, >, >=,
mod, div
4.3.8- Analyse the use of variables,
constants and operators in
algorithms
Example:

You might also like