Practice question · Sort into groups
A set of instructions counts as a genuine algorithm only if it is finite (it always stops) and definite (every step is unambiguous). Sort each description.
Groups: Is a valid algorithm · Not an algorithm
- Keep guessing a number until it feels right
- Double x, then subtract 3, then halt
- Repeat 'add 1 to x' forever
- For each item in the list, swap it with its neighbour if larger, then stop
Hints
- Test each one against two demands: does it terminate, and is every step precise?
- A step that says 'somehow' or 'until it feels right' fails definiteness; a loop with no exit fails finiteness.
Show the answer
Is a valid algorithm: For each item in the list, swap it with its neighbour if larger, then stop, Double x, then subtract 3, then halt
Not an algorithm: Keep guessing a number until it feels right, Repeat 'add 1 to x' forever
Why
A valid algorithm must be finite and definite. 'Guess until it feels right' and 'do something clever' are not definite, and 'repeat forever' is not finite. The others give an exact, terminating recipe.
Practise What Makes an Algorithm Good
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on What Makes an Algorithm Good
- The lesson says an algorithm must be finite and definite. Select every description that violates at least one…
- An O(n log n) sort loses to an O(n²) insertion sort on a 20-element array, and every production sort library…
- Match each quality or property to its meaning.
- Order the recommended design workflow, which puts correctness before speed.