0% found this document useful (0 votes)
5 views3 pages

Introduction to Algorithmic Thinking

The document discusses algorithms and provides examples. It defines an algorithm, lists characteristics of a good algorithm, and gives recipes and calculating rectangle surface as examples. Instructions for writing algorithms are provided, including naming the algorithm, defining inputs and outputs, and listing the step-by-step process.

Uploaded by

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

Introduction to Algorithmic Thinking

The document discusses algorithms and provides examples. It defines an algorithm, lists characteristics of a good algorithm, and gives recipes and calculating rectangle surface as examples. Instructions for writing algorithms are provided, including naming the algorithm, defining inputs and outputs, and listing the step-by-step process.

Uploaded by

fokam miguel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER : INITIATION TO ALGORITHMIC THINKING

Objectives:
- Writing basic solution procedure to problems
- Ordering solution steps
Lesson : Introductive Activity; Cook recipe INTRODUCTION
Algorithm is a part of our daily life. We accomplish any task by following an algorithm. For example
making a cake, Computing rectangle surface.
Computer science is based in programs or applications whose execution can be summarized as:
problem posed – analysis – algorithm – program – compilation – execution.
An Algorithm is a well-defined step by steps instructions specifying how to complete a task.
1 DEFINITION
An algorithm is a well-defined set of step-by-step instructions for solving a problem in a finite
amount of time. A set of instructions is not an algorithm if there is no definite stopping place, or if
the instructions are too vague to be followed clearly. An algorithm cannot be directly executed by a
computer, but it has to be translated into a program using a programming language.
2 CHARACTERISTICS OF A GOOD ALGORITHM A good algorithm:

- should be explicit (i.e. clear and obvious)


- should be precise (i.e. exact and accurate)
- should be unambiguous (i.e. no doubts about what to do/ only one way of interpreting the
instructions)
- should be effective (i.e. produce good results)
- should be finite (i.e. have a definite stopping place)
3 INTRODUCE ACTIVITY: COOK RECIPE
1. PROBLEM TO SOLVE OR TASK TO PERFORM: state the step by step instructions to follow in order
to obtain at the end the pineapple juice. Specify the input elements, the result or the output of your
algorithm.
2. SOLUTION
- This define the problem to solve: how to make pineapple juice
- The definite stopping point: when the juice is done
- The above activity is an algorithm to prepare a pineapple juice.
- Pineapple juice is the output
- The ingredients constitute the Input
- The cooking steps represents the instructions steps.

RECIPE
- 1 lemon- 1 orange- 1 pineapple- 1 litter of water- 3 eating spoon
INGREDIENTS (inputs)
of sugar- 1 eating spoon of grated ginger
- Wash lemon and orange- Cut them into small pieces and put
COOKING(set of them to the fridge- Peel the pineapple and cut them into small
instructions) pieces- Mix the pieces of lemon, orange, pineapple, water, grated
(processes) ginger;- Grind them- Sleeve it to extract the juice- Then put the
juice into the fridge

Output PINEAPPLE JUICE (Output)

EXERCISE: write and algorithm to make a cup of tea Solution: Algorithm Making _ a_cup_ of_ tea
Inputs: Sugar, water, ovaltin, milk, fire Set of instructions:
1- Prepare the Fire

2- Put the pot on the fire


3- Boil water
4- Put the milk, Ovaltin, sugar inside the tea cup
5- Add the boil water to it
6- Stir to make sure that it is uniform
7- Test the tea if it is not OK perform step 4 Else END Drink your tea

Lesson 2 : Examples of Algorithms


1 Structure of an Algorithm
To write an algorithm, you have to specify:
- The name of the algorithm which has to be clear and explicit. It should clearly present the problem
to be solve.
- The inputs that represents data we need to solve the problem.
- The set of instructions : that explains how to solve the problem
- The Output: That represents the final result we should obtain.
2 Example of algorithm: Calculating the surface of a rectangle PROBLEM: Write an algorithm that
calculate the surface of a rectangle SOLUTION:
Algorithm : Surface_of_a_Rectangle;
INPUTS: Width: W;
Height: H;
Begin(SET OF INSTRUCTIONS:)
1. PROMPT USER TO ENTER WIDTH AND HEIGHT
2. READ THE WIDTH AS W AND THE HEIGHT AS H
3. COMPUTE THE SURFACE BY MULTIPLYING THE HEIGHT H BY THE WIDTH W
4. STORE THE RESULT AS S=H×W
PRINT THE SURFACE S
END.
1- Exercise: Write an algorithm to calculate the surface of a square.

Common questions

Powered by AI

The algorithm for calculating the surface of a square should include: 1. Prompting the user to enter the length of a side [Logically inferred from Source 2]. 2. Reading the length as L [Logically inferred from Source 2]. 3. Calculating the surface by squaring the length (S = L x L) [Logically inferred from Source 2]. 4. Printing the surface as output [Logically inferred from Source 2]. These steps ensure the algorithm addresses input acquisition, processing, and result dissemination, mirroring the logical structure used for calculating a rectangle's surface .

Algorithmic thinking and following a cooking recipe share a structural similarity as both involve a defined set of steps to reach a desired outcome. A cooking recipe has inputs (ingredients), a process (cooking steps), and an output (finished dish). Similarly, an algorithm involves inputs (data), a process (instructions), and outputs (results). The structural components, such as clear objectives and precise steps, are fundamental to both to ensure success and reliability in achieving the end goal .

Defining explicit inputs and outputs in algorithms is crucial as it determines the data needed for execution and the expected result, guiding the entire process of algorithm design. For example, in making pineapple juice, inputs like fruits and water directly affect the quality and quantity of the output (juice). Similarly, in calculating a rectangle's surface, the width and height are essential inputs to obtain an accurate result (area of the rectangle). Clear definitions avoid confusion, improve accuracy, and ensure that users understand what data is required and what results to expect, thus enhancing the algorithm’s reliability and efficacy .

The precision of algorithms ensures tasks are performed with accuracy and predictability, which is beneficial in reducing errors and enhancing efficiency, especially in repetitive or complex tasks . However, this precision can also be a limitation as it may not allow for flexibility or adaptation to unforeseen circumstances. For instance, any deviation from the input requirements or steps could result in failure or incorrect results, limiting the algorithm’s applicability to dynamic environments or situations requiring human intuition and judgment .

A good algorithm should be explicit, precise, unambiguous, effective, and finite. Explicitness ensures clarity and understanding, allowing users to follow instructions easily . Precision ensures accuracy in execution, preventing errors . Unambiguity guarantees that instructions can be interpreted only one way, reducing confusion . Effectiveness ensures the algorithm produces the desired result efficiently . Finally, finiteness guarantees that the algorithm will terminate after a certain number of steps, thus ensuring usability and practicality .

In the pineapple juice preparation algorithm, the inputs include lemon, orange, pineapple, water, grated ginger, and sugar . The processes consist of washing, cutting, mixing, grinding, and refrigerating the ingredients . The output is the finished pineapple juice . These components ensure the algorithm is complete by defining what is necessary to complete the task (ingredients), how it is done (method), and what the result should be (juice), thus encompassing all aspects to reach the intended outcome .

Algorithms can apply to everyday life and other disciplines by providing structured solutions to repetitive tasks. For instance, a morning routine can be viewed as an algorithm, with inputs such as toothbrush and toothpaste, and steps including brushing, washing, and dressing, leading to the output of being ready for the day . In fields like education, algorithms could structure a study plan by outlining learning objectives (inputs), steps for study and review (process), leading to improved academic performance (output). This structured approach can optimize time, resources, and improve outcomes across various contexts .

To modify an algorithm for preparing pineapple juice into one for preparing a mixed fruit salad, logical transitions would include changing both inputs and processes. The inputs would expand to include a variety of fruits for the salad, like berries or apples, instead of solely using tropical fruits like pineapple . The processes would adapt to steps such as washing, peeling, slicing, and mixing the fruits, rather than grinding and juicing . The output also changes from liquid juice to a solid fruit salad. These transitions ensure the algorithm remains coherent with the new task while retaining structure and coherence .

Having a finite stopping point is necessary to ensure that an algorithm concludes after a defined number of steps, which guarantees that it will produce a result within a reasonable time frame . This prevents scenarios where the algorithm could potentially run indefinitely, which would be impractical for real-world applications and computational resources . Consequently, when designing an algorithm, this necessitates careful consideration of loop terminations and conditional statements to ensure the algorithm halts under all expected conditions .

The Structure of an Algorithm provides a framework that includes naming the algorithm, defining inputs, setting instructions, and determining outputs . This methodical approach ensures that computational tasks are well-defined, with clear objectives and processes, enhancing understanding and implementation. Naming helps in articulating the problem context, inputs define necessary data, instructions outline the procedure, and outputs signify the expected outcome, thus ensuring completeness and coherence in solving computational tasks .

You might also like