Skip to content
MathsGenie logo
Open app

Course home

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

Algorithms

EasyMedium
123456789101112131415161718
Question 2

A programmer is writing an algorithm tool to select the smallest suitable server capacity for a client's storage requirements.

2 SET serverLimits TO [250, 500, 1000, 2000]
3 SET ptr TO 0
4 SET allocated TO FALSE
5
6 SEND "Enter required storage (GB)" TO DISPLAY
7 RECEIVE reqStorage FROM (INTEGER) KEYBOARD
8
9 WHILE (NOT allocated) DO
10     IF (serverLimits[ptr] >= reqStorage) THEN
11         SEND serverLimits[ptr] TO DISPLAY
12         SET allocated TO TRUE
13     ELSE
14         SET ptr TO ptr + 1
15     END IF
16 END WHILE
17
18 IF (NOT allocated) THEN
19     SEND "No suitable server found" TO DISPLAY
20 END IF

The algorithm fails with an index error if a user inputs a storage requirement of 3000.

Construct a single line of pseudocode to correct the logic error in line 9.

[2]

Algorithms Questions

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