Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Algorithms

EasyMedium
123456789101112131415161718
Question 4

A developer is writing a shipping dispatch program to categorize packages based on their weight. She writes two different algorithms to achieve this, shown in Figure 1 and Figure 2.

Figure 1

1  SEND 'Enter package weight: ' TO DISPLAY
2  RECEIVE weight FROM (REAL) KEYBOARD
3  IF (weight < 5.0) THEN
4      SEND 'Standard courier' TO DISPLAY
5  ELSE
6      IF (weight <= 15.0) THEN
7          SEND 'Heavy courier' TO DISPLAY
8      ELSE
9          SEND 'Freight cargo' TO DISPLAY
10     END IF
11 END IF

Figure 2

1  SEND 'Enter package weight: ' TO DISPLAY
2  RECEIVE weight FROM (REAL) KEYBOARD
3  IF (weight < 5.0) THEN
4      SEND 'Standard courier' TO DISPLAY
5  END IF
6  IF (weight >= 5.0) AND (weight <= 15.0) THEN
7      SEND 'Heavy courier' TO DISPLAY
8  END IF
9  IF (weight > 15.0) THEN
10     SEND 'Freight cargo' TO DISPLAY
11 END IF

Explain why the algorithm in Figure 1 is more efficient than the algorithm in Figure 2.

[2]

Algorithms Questions

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