Data Structure - Lesson 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Lesson 1

Introduction to Algorithms and the characteristics of algorithm

Let’s Start.

 What are data structures and algorithms?


 What are the characteristics of algorithms?
 Write an algorithm to solve tasks in everyday problems

Let’s Think IT and Reflect!


If we used algorithm to solve the problem:

 How the algorithms solve task in your everyday problems?

 What did you do to understand the instruction? Where you able to perform the task
after?
Let’s Level IT UP!

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 the fig 1 below. 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 includes:

1. derivation of an algorithm that solves the problem, and


2. conversion of the algorithm into code.

It is worth noting that;

1. an algorithm is a sequence of steps, not a program.


2. 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 following ways;

a. human language
b. pseudo code
c. flow chart
EXAMPLE

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.

Characteristics of an Algorithm

There following are some key characteristics of an algorithm

1. Each step of an algorithm must be exact; this means that an algorithm must be precise and
ambiguously described. This eliminates any uncertainty. it can also be said to the
characteristic of precision, i.e. the steps are precisely stated(defined).
2. Algorithm must terminate; since the ultimate aim of an algorithm is to solve a problem,
then it must terminate otherwise there won’t be a solution for the problem. This leads to
the fact that an algorithm must have a finite number of steps in its execution. the presence
of endless (infinite) loops must be avoided
3. An algorithm must be effective; this means that an algorithm must provide the correct
answers at all times
4. An algorithm must be general; this means that an algorithm must solve every instance of a
problem
5. Uniqueness: results of each step are uniquely defined and only depend on the input and
the result of the preceding steps.
6. Finiteness: the algorithm stops after a finite number of instructions are executed.
7. Output: the algorithm produces output

Reading Assignment: Introduction to Algorithms and the characteristics of algorithm

Activity 1.1.1

Below are the steps of the program process, you need to create a simple program that
will display the value of max. This is in a form of a short video. You may use an actual code and
show your output.

1. Set max to 0.
2. For each number x in the list L, compare it to max. If x is larger, set max to x.
3. max is now set to the largest number in the list.
1. Outline the algorithmic steps that can be used to add given numbers
2. By using an example, describe how the concept of algorithms can be well presented to a
group of students being introduced
3. With the aid of an appropriate example, explain the characteristics of algorithms

SUGGESTED READING

 V. Das, (2008). Principles of Data Structures and Algorithms using C and C++
 SAMS. (1999). Teach Yourself Data Structures and Algorithms In 24 hours.
 Data Structures. (2010). Using C++, Second Edition, D.S. Malik,

You might also like