2.1.7

Correcting Algorithms

Test yourself

Correcting Algorithms

As well as knowing what an algorithm does, it's important to be able to fix it if it all goes wrong.

Illustrative background for Incorrect identifiersIllustrative background for Incorrect identifiers ?? "content

Incorrect identifiers

  • A common mistake in programs is incorrect identifiers.
  • Be very careful with uppercase and lowercase letters.
  • Be careful with similar looking characters:
    • 0 and O.
    • 1 and l (lower case L).
Illustrative background for Incorrect operatorsIllustrative background for Incorrect operators ?? "content

Incorrect operators

  • Look out for the difference between similar operators such as testing if a number is less than another, rather than less than or equal to the other.
Illustrative background for Missing processesIllustrative background for Missing processes ?? "content

Missing processes

  • Sometimes a line of code has been forgotten, which can lead to issues such as infinite loops, where the code will never end.

Examples of how to Correct Algorithms

Illustrative background for Incorrect identifiersIllustrative background for Incorrect identifiers ?? "content

Incorrect identifiers

  • In this example, there is a problem on line 1.
  • Weather has initially been misspelt.
  • If the program were to run, the programmer would see an error indicating that there is no variable named waether. So, the program can not see if the value of sun is stored within the weather variable.
Illustrative background for Incorrect operatorsIllustrative background for Incorrect operators ?? "content

Incorrect operators

  • This code determines whether a number is odd or even.
    • A number is even if it is EXACTLY divisible by 2 with NO REMAINDER.
  • The error is on line 3.
  • Whilst >= does include 0, it also includes the only other answer of 1.
  • If this program were to be run, all numbers would be shown as even.
  • To fix the code, we need to replace > with =

Jump to other topics

1Computer Systems

1.1Systems Architecture

1.2Memory & Storage

1.3Computer Networks, Connections & Protocols

1.4Network Security

1.5Systems Software

1.6Ethical, Legal, Cultural & Environmental Concern

2Computational Thinking, Algorithms & Programming

2.1Algorithms

2.2Programming Fundamentals

2.3Producing Robust Programs

2.4Boolean Logic

2.5Programming Languages & IDEs

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium