26.2: Activity 1 - Introduction to Algorithms and Problem Solving
-
- Last updated
- Save as PDF
Introduction
In this learning activity section, the learner will be introduced to algorithms and how to write algorithms to solve tasks faced by learners or everyday problems. Examples of the algorithm are also provided with a specific application to everyday problems that the learner is familiar with. The learners will particularly learn what is an algorithm, the process of developing a solution for a given task, and finally examples of application of the algorithms are given.
Algorithm
An algorithm is a finite sequence of steps for accomplishing some computational task. It must
- Have steps that are simple and definite enough to be done by a computer, and
- Terminate after finitely many steps.
An algorithm can be considered as a computational procedure that consists of a set of instructions, that takes some value or set of values, as input, and produces some value or set of values, as output, as illustrated in Figure 1.3.1 . It can also be described as a procedure that accepts data, manipulate them following the prescribed steps, so as to eventually fill the required unknown with the desired value(s). The concept of an algorithm is best illustrated by the example of a recipe, although many algorithms are much more complex; algorithms often have steps that repeat (iterate) or require decisions (such as logic or comparison) until the task is completed. Correctly performing an algorithm will not solve a problem if the algorithm is flawed or not appropriate to the problem. A recipe is a set of instructions that show how to prepare or make something, especially a culinary dish.
Different algorithms may complete the same task with a different set of instructions in more or less time, space, or effort than others. Algorithms are essential to the way computers process information, because a computer program is essentially an algorithm that tells the computer what specific steps to perform (in what specific order) in order to carry out a specified task.
Algorithmic problem solving comes in two phases. These include:
- derivation of an algorithm that solves the problem, and
- conversion of the algorithm into code.
It is worth noting that:
- an algorithm is a sequence of steps, not a program.
- same algorithm can be used in different programs, or the same algorithm can be expressed in different languages, because an algorithm is an entity that is abstracted from implementation details.
An algorithm can be expressed in the following ways:
- human language
- pseudo code
- flow chart
Example \(\PageIndex{1}\)
Problem: Given a list of positive numbers, return the largest number on the list.
Inputs: A list L of positive numbers. This list must contain at least one number.
Outputs: A number n, which will be the largest number of the list.
Algorithm
- Set max to 0.
- For each number x in the list L, compare it to max. If x is larger, set max to x.
- max is now set to the largest number in the list.
Conclusion
The learner was introduced to the concept of algorithms and the various ways he/she can develop a solution to a task. In particular, the learner was introduced to the definition/s of an algorithm, the three main ways of developing or expressing an algorithm which are the human language, Pseudo code and the flow chart. An example was also given to reinforce the concept of the algorithm.
Assessment
- Outline the algorithmic steps that can be used to add two given numbers.
- By using an example, describe how the concept of algorithms can be well presented to a group of students being introduced to it.