Skip to content

Course home

Algorithms

Algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
Question 72

A shipping program, ShipClassify, categorizes packages according to weight limits in grams.

Here is the pseudo-code for an algorithm that determines the delivery category of a package.

1 SET weightThresholds TO [100, 250, 500, 1000]
2 SET shippingCategory TO ["Standard", "Express", "Priority", "Overnight", "Heavy Freight"]
3 SET sorted TO False
4 SET index TO 0
5
6 SEND "Enter package weight in grams" TO DISPLAY
7 RECEIVE weight FROM (INTEGER) KEYBOARD
8
9 WHILE (sorted = True) AND (index < LENGTH(weightThresholds)) DO
10     IF (weight > weightThresholds[index]) THEN
11         SET index TO index + 1
12     ELSE
13         SET sorted TO True
14     END IF
15 END WHILE
16 SEND shippingCategory[index] TO DISPLAY

The pseudo-code produces an incorrect output.

When the user enters 350, the algorithm outputs "Standard". The correct output should be "Priority".

State the name for this type of error.

[1]
Markscheme

Algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Algorithms

159 exam-style questions on Edexcel GCSE Computer Science Algorithms, covering Constructs for solving problems, Variables, constants and data structures, Arithmetic, relational and logical operators, Tracing algorithm output with trace tables, Types of error and correcting logic errors, Standard algorithms (sorts and searches), and Evaluating algorithm fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank