Tutorial 1
Section A
1. What is an algorithm?
The step by step sequence of instructions that describe how the data is to be processed to
produce the desired output.
2. Explain need of an algorithm.
To fully understand the requirements and the input needed before coding the solution. To solve
problem.
3. Can there be more than one algorithm for a single problem? Give reason for your answer.
Yes, because different algorithm for a single problem will only differ in their efficiency of
the problem solving. Give example = path from a to z, there are many alternative ways
4. Determine a step-by-step procedure (list the steps) to do the following tasks:
a) Fix a flat tire. 1. Take out the jack & spare tire.
2. Jack-up the car.
3. Take off the flat tire.
4. Put on the spare tire.
5. Lower the jack.
6. Replace the jack & put the flat tire away.
b) Make a 1. Pick up the phone.
telephone call. 2. Dial in the number.
3. Press the call button.
4. Wait for the network to connect.
5. If connection is successful, you will hear the dialler tone,
Else if network connection failure, number will not be dialled
Else if number is busy, hear busy tone
Else if number is not reachable, hear number not reachable message.
c) Log on to a 1. Press the power button on the computer.
computer. 2. If a password is required, typed it in.
3. Press enter
4. Log on complete.
d) Roast a turkey 1. Prepare the turkey for roasting.
2. Preheat the oven to 450°F.
3. Add liquid to the roasting pan.
4. Place the turkey in the oven and turn down the heat.
5. Roast the turkey for about three and a half hours.
6. Baste the turkey every 45 minutes.
7. Check the turkey's temperature after finished roasting.
8. Rest the turkey for 30 minutes.
9. Serve 6 people.
5. Are the procedures you developed in question number 4 considered as algorithms? Discuss why
or why not.
Yes, because it is the exact step by step procedures to complete each tasks respectively.
6. Explain uses of Flowchart.
To show the flow of instructions in an algorithm using special symbols
7. Draw a flowchart to find the area of a circle of radius r.
Start
Input the
radius of
the circle,
Radius = r
Calculate the area of the
circle:
Area of circle = 3.142 x (r^2)
Display the
area of the
circle
End
8. Draw a flowchart to find the largest of three numbers A, B and C.
Start
Input the
value A, B
and C
No Yes
Is Is Is
B>C? A>B? A>C?
No Yes
No Yes
Display Display Display Display
C as the B as the C as the A as the
largest largest largest largest
number number number number
End
9. Draw a flowchart to convert temperature Fahrenheit to Celsius.
Start
Input the
temperature in
Fahrenheit, F
Convert Fahrenheit to
Celsius, C:
C = (F-32) (5/9)
Display the
temperature
in Celsius
End
Section B
Complete the problem definition for the following problems. Identify what is the required information,
what are the data needed, what formulas are involved. Write algorithm (pseudocode and flowchart) for
each of the following problems.
1. Task: Calculate the areas of the three squares.
The result of problem definition:
Information Areas of the three squares A, B and C
Formula Area = side^2
Data to Side of squares A, B and C
enter
Pseudocode:
1. Input the side of squares A, B and C.
2. Calculate the area of the squares by squaring its side:
Area =side^2
3. Display the areas of the three squares.
Start
Input the side
of squares A, B
and C
Calculate the area of
squares A, B and C:
Area = side^2
Print the
area of the
three
squares
End
2. Task: Calculate the total salaries for 5 employees. The salary is paid based on the hours they worked
and the rate per hour using the formula salary = rate per hour x hours worked. Each employee is being
paid with the same rate.
The result of problem definition:
Information Total salaries for 5 employees
Formula Salary = rate per hour x hours worked
Total salary = sum of 5 employees’ salaries
Data to Hours worked of each employee and rate per houyr
enter
Pseudocode:
1. Input the hours worked for each employee and rate per hour
2. Calculate the salary of each employee by multiplying rate per hour with hours worked:
Salary = rate per hour x hours worked
3. Sum the salaries of the 5 employees:
4. Print the total salaries for 5 employees
Start
Input the hours
worked of each
employees and
rate per hour
Calculate each salary of the
5 employees:
Salary= rate per hour x
hours worked
Sum the salaries of all
employees
Print the total
salaries
for 5
employees
3. Calculate the temperature in Celsius. Temperature in Fahrenheit will be entered. The formula is:
End – 32).
Temperature in Celsius = 5/9 (temperature in Fahrenheit
The result of problem definition:
Information Convert from Fahrenheit to Celsius
Formula Temperature in Celsius = 5/9 (temperature in Fahrenheit – 32).
Data to Temperature in Fahrenheit
enter
Pseudocode:
1. Input the temperature in Fahrenheit.
2. Calculate the temperature into Celsius:
Celsius = (5/9) (temperature in Fahrenheit – 32)
3. Print the temperature in Celsius.
Start
Input the
temperature in
Fahrenheit, F
Convert Fahrenheit to
Celsius, C:
C = (5/9) (F-32)
Print the
temperature
in Celsius
End