Professional Documents
Culture Documents
HND in Computing and Software Engineering: Lesson 02 - Introduction To Algorithms
HND in Computing and Software Engineering: Lesson 02 - Introduction To Algorithms
Engineering
SEC5213: Data Structures and Algorithm
Level: 5
Credit Value: 20
1
Lecturer: Ms. Sathananthy 06/04/2022
Learning Outcome 02
2 06/04/2022
Outline
Fundamentals of Algorithms
Performance of an algorithm
Characteristics of an algorithm
7
Algorithm
4 06/04/2022
Algorithm – problem solving
5 06/04/2022
Algorithm – problem solving
Algorithm:
Step 1: Read number N,
Step 2: Set remainder as N modulo 2,
Step 3: If remainder is equal to 0 then number N is even, else
number N is odd,
Step 4: Print output
6 06/04/2022
Algorithm – problem solving
Algorithm:
point
Algorithm:
Step 1: Enter www.facebook.com in your browser. (I/O)
1. Draw four line segments through the 9 points without lifting your pencil or
retracing a line
9 06/04/2022
Miscellaneous problems solving
There are three brothers named John, James and William, who look exactly alike. John
and James always lie, but William always tells the truth. You meet one of the brothers
on the street one day, and want to know if he is John (because John owes you money).
You are allowed to ask ONE question that can be answered “yes” or “no”, but the
question may not contain more than 3 words. What question would you ask?
10 06/04/2022
Solution
The questions would be, “Are you James?”(The goal is to find John, the one that
If the person is John, he will say “Yes”(he owes you money and he lies)
If the person is William, he will say “No”(he tells the truth)
So, if the answer is “yes” you know that it is John and you can then demand your
money.
You have a 50% probability of knowing if it is James with this question.
11 06/04/2022
Miscellaneous problems solving
Three men are condemned to die, one of whom is blind. The king decides he will offer them an
opportunity to be set free. The three men are arranged in a circle facing one another. The king
produces 5 hats: 2 black and 3 white. The king places a hat on the head of each person and then
destroys the two remaining hats. The men have no idea which hats have been destroyed. The
king instructs them, “The first one of you who can tell me the color of his hat will be set free.” A
period of time passes in silence and then finally the blind man tells the king the color of his hat
and is set free. What color hat was the blind man wearing and how did he know?
12 06/04/2022
Characteristics of an Algorithm
Output: An algorithm must have 1 or well defined outputs, and should match with the
desired output.
Feasibility: An algorithm must be terminated after the finite number of steps.
16
Next – Asymptotic Analysis
17 06/04/2022