Previous Module
Next Module

COMPUTER SYSTEMS: Encoding and compression

COMPUTER SYSTEMS: Network topologies

COMPUTER SYSTEMS: Wired and wireless networks, protocols, and layers

COMPUTER SYSTEMS: Threats to computer systems and networks

COMPUTER SYSTEMS: Operating systems and utility software

COMPUTER SYSTEMS: Impact of technology on society

ALGORITHMS AND PROGRAMMING: Types of data

ALGORITHMS AND PROGRAMMING: Producing robust programs

ALGORITHMS AND PROGRAMMING: Designing, creating, and refining algorithms

ALGORITHMS AND PROGRAMMING: Programming languages

  • Turning a designed algorithm into executable code requires the correct syntax and an accurate translation of logic.
  • Refining an algorithm can involve: 
    • Improving an algorithm after testing it 
    • Fixing logic or adding validation
    • Optimising performance or clarity 
  • For example:
    • Original code doesn’t check for empty input → add a condition to handle it. 
    • Original algorithm uses multiple nested ifs → simplify with elif.

# Original algorithm

age = int(input(“Enter age:”))

print(“Age recorded”)

 
 

# Refined algorithm

age = int(input(“Enter age:”))

 
 

if age < 0 or age > 120:

print(“Invalid age”)

else:

print(“Age recorded”)

  • Refinement is often based on test results. More refined algorithms be easier to read and maintain but may have more or fewer steps depending on whether more specificity or efficiency is needed.

# Original algorithm

numbers = [2, 4, 6, 8]

total = 0

 
 

for i in range(0, len(numbers)):

total = total + numbers[i]

 
 

print(total)

 
 

# Refined algorithm

numbers = [2, 4, 6, 8]

total = sum(numbers)

 
 

print(total)

Unlock Refining algorithms

Subscribe to SnapRevise+ to get immediate access to the rest of this resource.

Premium accounts get immediate access to this resource.

Previous Module
Next Module