0% found this document useful (0 votes)
3 views11 pages

Chapter 7 Algorithm Design Worksheet

The document is a worksheet focused on Algorithm Design and Problem Solving, covering topics such as the program development life cycle, flowcharts, pseudocode, validation, verification, and standard algorithms. It includes a series of questions and exercises aimed at reinforcing understanding of these concepts, with sections dedicated to defining terms, decomposing systems, writing pseudocode, and testing data. Additionally, it provides an answer key for self-assessment.
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)
3 views11 pages

Chapter 7 Algorithm Design Worksheet

The document is a worksheet focused on Algorithm Design and Problem Solving, covering topics such as the program development life cycle, flowcharts, pseudocode, validation, verification, and standard algorithms. It includes a series of questions and exercises aimed at reinforcing understanding of these concepts, with sections dedicated to defining terms, decomposing systems, writing pseudocode, and testing data. Additionally, it provides an answer key for self-assessment.
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

Paper 2 Worksheet: Chapter 7

Algorithm Design and Problem Solving


Student Name: __________________________ Date: _______________

Time suggestion: 2 hours 15 minutes for full worksheet, or split into four 35-minute sessions.

Exam focus: pseudocode, flowcharts, trace tables, validation/verification, test data, error correction, standard
algorithms and algorithm-writing.

A. Quick Revision Checklist


• Program development cycle: analysis, design, coding, testing. Maintenance is part of the full life cycle but this
chapter focuses mainly on the first four stages.
• Analysis uses abstraction and decomposition. Abstraction removes unnecessary detail; decomposition breaks a
problem into smaller parts.
• Top-down design breaks a system into sub-systems using structure diagrams. Each lower level gives more detail.
• Every system can be described using inputs, processes, outputs and storage.
• Flowcharts use terminator, process, input/output, decision and flow line symbols.
• Pseudocode uses clear English-like keywords such as INPUT, OUTPUT, IF, CASE, FOR, REPEAT and WHILE.
• FOR loops are used when the number of repetitions is known. REPEAT loops always run at least once. WHILE
loops may run zero times.
• Standard methods: totalling, counting, maximum, minimum, average, linear search and bubble sort.
• Validation checks if data is reasonable before it is accepted. Verification checks that data has been copied
accurately.
• Test data includes normal, abnormal, extreme and boundary data.
• A trace table records every change in variables and every output during a dry run.
• When correcting algorithms, check variable names, loop conditions, missing INPUTs, wrong comparisons, wrong
output and wrong loop endings.

Section 1: Program Development Life Cycle


1. Define the following terms. [8]
Term Definition
Analysis
Design
Coding
Testing
Abstraction
Decomposition
Requirements specification
Iterative testing
2. A school wants a program to calculate monthly fee payments for students. Complete the table by writing one activity
done at each stage. [4]
Stage Activity for school fee program
Analysis
Design
Coding
Testing
3. Explain the difference between abstraction and decomposition using a real-life example. [4]

Chapter 7 Worksheet – Algorithm Design and Problem Solving


________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Section 2: Computer Systems, Sub-systems and Decomposition


4. Decompose an online food ordering system into inputs, processes, outputs and storage. [8]
Component Examples
Inputs
Processes
Outputs
Storage
5. Draw a structure diagram for a library borrowing system. It must include: search book, borrow book, return book,
calculate fine, print receipt. Add at least two lower-level sub-systems. [6]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
6. State two advantages of top-down design when a large program is being developed by a team. [2]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Section 3: Flowcharts and Pseudocode Basics


7. Match each flowchart symbol to its purpose. [5]
Symbol name Purpose
Terminator
Process
Input/Output
Decision
Flow line
8. Write pseudocode assignment statements for the following. [5]
Part Task Pseudocode
a Store 50 in variable Mark
b Add 1 to Counter
Calculate TotalPrice from Quantity
c
multiplied by Price
d Store the string Ali in Name
e Store TRUE in Found
9. Complete the table of operators. [8]
Operator Meaning
>
<
=
>=
<=
<>
AND

Chapter 7 Worksheet – Algorithm Design and Problem Solving


OR

Section 4: Selection: IF and CASE


10. Write pseudocode that inputs Age. If Age is less than 18, output "Child", otherwise output "Adult". [4]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
11. Write pseudocode that inputs a mark from 0 to 100. Output "Invalid" if it is outside the range, "Pass" if it is 50 or
more, otherwise output "Fail". [6]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
12. Use CASE OF to output the day name when DayNo is 1 to 7. Output "Invalid day" for any other number. [7]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Section 5: Iteration / Loops


13. Complete the table. [6]
Loop When is it used? Runs at least once?
FOR ... TO ... NEXT
WHILE ... DO ... ENDWHILE
REPEAT ... UNTIL
14. Write a single FOR loop to output the numbers 1 to 20. [3]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
15. Write pseudocode to repeatedly input a password until its length is at least 8 characters. [5]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
16. Rewrite this REPEAT loop as a WHILE loop. [5]

Chapter 7 Worksheet – Algorithm Design and Problem Solving


REPEAT
INPUT Num
UNTIL Num > 0

________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Section 6: Standard Methods of Solution


17. Complete the missing parts of this totalling algorithm. It inputs 10 marks and outputs the total. [5]
Total ← ________
FOR Counter ← 1 TO ________
INPUT Mark
Total ← Total ________ Mark
________ Counter
OUTPUT ________

18. Write pseudocode to input 20 numbers and count how many are greater than 100. [6]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
19. Write pseudocode to input 10 numbers and output the highest and lowest number. Your algorithm should work
even if the numbers are negative. [10]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
20. A class has 30 marks stored in Mark[1:30]. Write pseudocode to calculate and output the average mark. [5]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
21. Linear search: The array StudentName[1:40] stores student names. Write pseudocode to input a name and output
"Found" or "Not found". [8]

Chapter 7 Worksheet – Algorithm Design and Problem Solving


________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
22. Bubble sort: Fill in the missing words/statements to sort Score[1:8] in ascending order. [8]
Last ← 8
REPEAT
Swap ← FALSE
FOR Index ← 1 TO Last - 1
IF Score[Index] ________ Score[Index + 1]
THEN
Temp ← Score[Index]
Score[Index] ← __________________________
Score[Index + 1] ← __________________________
Swap ← ________
ENDIF
NEXT Index
Last ← Last - 1
UNTIL (NOT Swap) OR Last = ________

Section 7: Validation and Verification


23. Explain the difference between validation and verification. Give one example of each. [4]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
24. Complete the validation checks table. [12]
Validation check What it checks Example
Range check
Length check
Type check
Presence check
Format check
Check digit
25. For each input, suggest suitable validation check(s) and give a reason. [8]
Input Validation check(s) Reason
Exam mark 0 to 100
Email address must not be blank
Product code AB123
Password 8 to 12 characters
26. Write pseudocode to input Age for a ride. Age must be greater than 7 and less than 12. Keep asking until a valid
age is entered. [6]
________________________________________________________________________________
________________________________________________________________________________

Chapter 7 Worksheet – Algorithm Design and Problem Solving


________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
27. Name two verification methods and describe how each works. [4]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Section 8: Test Data


28. Define these types of test data. [8]
Type of test data Definition
Normal data
Abnormal data
Extreme data
Boundary data
29. A program accepts whole number marks from 0 to 20 inclusive. Complete the test data table. [10]
Type Value(s) Expected result
Normal
Abnormal
Extreme lower
Extreme upper
Boundary data
30. A program checks if a ticket quantity is from 1 to 25 inclusive. Explain why each test value was chosen: 0, 1, 25,
26, 10. [5]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Section 9: Trace Tables and Dry Runs


31. Complete the trace table for the algorithm using test data: 5, 2, 9, 1, 7. [10]
Total ← 0
Highest ← 0
FOR Counter ← 1 TO 5
INPUT Number
Total ← Total + Number
IF Number > Highest
THEN
Highest ← Number
ENDIF
NEXT Counter
OUTPUT Total, Highest

Counter Number Total Highest OUTPUT


0 0
Chapter 7 Worksheet – Algorithm Design and Problem Solving
32. State the purpose of the algorithm in Question 31. [2]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
33. Dry run this algorithm and complete the trace table. Test data: 4, 7, 2, 8, 3, -1. [12]
Count ← 0
Total ← 0
INPUT Num
WHILE Num <> -1 DO
Count ← Count + 1
Total ← Total + Num
INPUT Num
ENDWHILE
OUTPUT Count, Total

Num Count Total OUTPUT


0 0

Section 10: Identifying and Correcting Errors


34. This algorithm should input numbers until 999 is entered. It should output numbers greater than or equal to 100,
but not output 999. Identify and correct four errors. [8]
INPUT Number
WHILE Numbers <> 999 DO
IF Number > 100
THEN
OUTPUT Number
ENDIF
ENDWHILE
OUTPUT Number

Error Correction
1
2
3
4
35. Correct the four error lines in this algorithm. It should input 10 valid marks from 0 to 100 and count how many
marks are passes. Pass mark is 50 or more. [8]
01 PassCount ← 0
02 FOR Index ← 1 TO 10
03 INPUT Mark
Chapter 7 Worksheet – Algorithm Design and Problem Solving
04 WHILE Mark < 0 AND Mark > 100 DO
05 INPUT Mark
06 ENDWHILE
07 IF Mark > 50 THEN PassCount ← PassCount + 1 ENDIF
08 UNTIL Index = 10
09 OUTPUT Index

Line number Correct code

Section 11: Cambridge-style Mixed Practice


36. Draw a flowchart for an algorithm that inputs numbers until 0 is entered. Negative numbers are ignored. Positive
numbers are counted. When 0 is entered, output the count and stop. [8]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
37. Explain the changes needed to also total the positive numbers. [2]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
38. Write a complete pseudocode algorithm for this problem. A shop sells up to 50 items in one transaction. Input the
price of each item. Reject any price below 0 or above 1000. Output total cost, highest price, lowest price and average
price. [15]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Chapter 7 Worksheet – Algorithm Design and Problem Solving
________________________________________________________________________________
39. Describe how you would test your algorithm in Question 38. Include normal, abnormal, extreme and boundary
data. [8]
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Chapter 7 Worksheet – Algorithm Design and Problem Solving


Answer Key / Mark Scheme
Q1. Analysis: investigates and defines requirements. Design: plans solution using structure
diagrams/flowcharts/pseudocode. Coding: writing the program. Testing: checking the program with test data.
Abstraction: keeping only relevant details. Decomposition: breaking a problem into smaller parts. Requirements
specification: clear statement of what the program must do. Iterative testing: test, amend and retest a module.

Q2. Analysis: identify inputs, outputs, calculations and storage. Design: plan algorithm/interface/data. Coding: write
program. Testing: use suitable test data and compare expected with actual results.

Q3. Abstraction removes unnecessary details; decomposition splits the problem into smaller tasks. Example answers
acceptable.

Q4. Inputs: customer details/order/payment/address. Processes: search menu, calculate total, apply delivery fee,
confirm order. Outputs: receipt/order confirmation/status. Storage: customers, menus, orders, payment reference.

Q6. Different programmers can work on different modules; modules are easier to test/debug; reduces development
time; makes complex problems manageable.

Q7. Terminator = start/stop; process = action/assignment; input/output = data entry or displayed/printed result; decision
= true/false branch; flow line = direction of control.

Q8. Mark ← 50; Counter ← Counter + 1; TotalPrice ← Quantity * Price; Name ← "Ali"; Found ← TRUE.

Q10. INPUT Age / IF Age < 18 THEN OUTPUT "Child" ELSE OUTPUT "Adult" ENDIF.

Q11. INPUT Mark / IF Mark < 0 OR Mark > 100 THEN OUTPUT "Invalid" ELSE IF Mark >= 50 THEN OUTPUT "Pass"
ELSE OUTPUT "Fail" ENDIF ENDIF.

Q12. CASE OF DayNo 1:"Monday" ... 7:"Sunday" OTHERWISE OUTPUT "Invalid day" ENDCASE.

Q13. FOR = known repetitions, not necessarily at least once if range invalid; WHILE = unknown repetitions, condition
at start, may run zero times; REPEAT = unknown repetitions, condition at end, runs at least once.

Q14. FOR Counter ← 1 TO 20 / OUTPUT Counter / NEXT Counter.

Q15. REPEAT INPUT Password UNTIL LENGTH(Password) >= 8. Also accept WHILE version.

Q16. INPUT Num / WHILE Num <= 0 DO INPUT Num ENDWHILE.

Q17. 0, 10, +, NEXT, Total.

Q18. Count ← 0 / FOR Counter ← 1 TO 20 / INPUT Number / IF Number > 100 THEN Count ← Count + 1 ENDIF /
NEXT / OUTPUT Count.

Q19. INPUT Number / Highest ← Number / Lowest ← Number / FOR Counter ← 2 TO 10 / INPUT Number / IF
Number > Highest THEN Highest ← Number ENDIF / IF Number < Lowest THEN Lowest ← Number ENDIF / NEXT /
OUTPUT Highest, Lowest.

Q20. Total ← 0 / FOR Counter ← 1 TO 30 / Total ← Total + Mark[Counter] / NEXT / Average ← Total / 30 / OUTPUT
Average.

Q21. INPUT Name / Found ← FALSE / Counter ← 1 / WHILE Counter <= 40 AND NOT Found DO IF
StudentName[Counter] = Name THEN Found ← TRUE ELSE Counter ← Counter + 1 ENDIF ENDWHILE / IF Found
THEN OUTPUT "Found" ELSE OUTPUT "Not found" ENDIF.

Q22. >, Score[Index + 1], Temp, TRUE, 1.

Chapter 7 Worksheet – Algorithm Design and Problem Solving


Q23. Validation checks data is reasonable before acceptance; example range check mark 0-100. Verification checks
copied data is accurate; example double entry or screen/visual check.

Q24. Range: between limits. Length: exact or allowed number of characters. Type: correct data type. Presence: not
blank. Format: matches pattern. Check digit: calculated digit detects entry/scanning errors.

Q25. Mark: range/type/presence. Email: presence and possibly format. Product code AB123: format/length. Password:
length/presence.

Q26. REPEAT INPUT Age IF Age <= 7 OR Age >= 12 THEN OUTPUT error ENDIF UNTIL Age > 7 AND Age < 12.

Q27. Double entry: enter data twice and compare. Screen/visual check: display entered data for user to confirm
against source.

Q28. Normal: accepted typical data. Abnormal: rejected invalid data. Extreme: smallest/largest accepted value.
Boundary: accepted and rejected values at limits.

Q29. Examples: normal 10 accepted; abnormal -5 or "ten" rejected; extreme 0 and 20 accepted; boundary -1 rejected,
0 accepted, 20 accepted, 21 rejected.

Q30. 0 just below lower boundary/rejected; 1 lower extreme/accepted; 25 upper extreme/accepted; 26 just above
upper boundary/rejected; 10 normal accepted.

Q31. Final output: Total 24, Highest 9. Total changes: 5,7,16,17,24. Highest changes: 5 then 9.

Q32. It totals five numbers and finds the highest number.

Q33. Inputs 4,7,2,8,3,-1. Count final 5, Total final 24, output 5,24.

Q34. Numbers should be Number; condition should allow >=100 so use Number >= 100; missing INPUT Number
inside loop after IF; final OUTPUT Number should be removed because it outputs 999.

Q35. Line 04: WHILE Mark < 0 OR Mark > 100 DO. Line 07: IF Mark >= 50 THEN PassCount ← PassCount + 1
ENDIF. Line 08: NEXT Index. Line 09: OUTPUT PassCount.

Q36. Flowchart should initialise Count to 0, input Number, if Number = 0 output Count and stop, if Number > 0
increment Count, loop back to input; if Number < 0 loop back without counting.

Q37. Initialise Total to 0; when Number > 0 add Number to Total; output Total with Count.

Q38. Award up to 15 marks: correct initialisation, loop up to 50, price validation, total, highest, lowest, average,
outputs, meaningful variables, comments.

Q39. Normal prices such as 10, 99.99; abnormal -1, 1001 or text; extreme 0 and 1000; boundary -0.01/0 and
1000/1000.01, plus expected results.

Chapter 7 Worksheet – Algorithm Design and Problem Solving

You might also like