Ignoring unnecessary information and focusing only on the important facts
Abstraction
Simplifies a problem to make it less complex
Makes the problem more straightforward to understand and create a solution
Decomposition
Breaking a problem down into smaller tasks so that it is easier to solve
Decomposition
Each individual problem can be separately tested and solved
Enables different people to work on the different parts of a larger problem that can later be recombined to produce a full solution
Algorithmic thinking
Following logical steps to solve the problem
Algorithmic thinking
1. Break down the problem using decomposition into smaller problems
2. Consider the required data and relevant data structures using abstraction
3. Follow logical steps to solve the problem
Algorithm
A set of instructions, presented in a logical sequence
Pseudocode
A method of defining algorithms
Flowcharts
A method of defining algorithms
OCR Exam Reference Language
The language used in OCR exams to represent algorithms
Algorithm design
Programmers create algorithm designs as a method of planning a program before writing any code. This helps them to consider the potential problems of the program and makes it easier to start creating source code.
Basic commands in OCR Exam Reference Language
Annotation
Assignment
Constants and Global Variables
Input / Output
Casting
Random Number
Selection (if-then-else)
if firstname == "Steven" then
print("Hello" + firstname)
elif firstname == "Steve" then
print("Please use full name")
else
print("Who are you?")
endif
Selection (case select)
switch day:
case "Sat":
print("It is Saturday")
case "Sun":
print("It is Sunday")
default:
print("It is a Weekday")
endswitch
Iteration (for loop)
for i = 1 to 10 step 1
input item
next i
Iteration (while loop)
while firstname != "Steven"
firstname = input("Try again:")
endwhile
Iteration (do while loop)
do
firstname = input("Guess name:")
until firstname == "Steven"
String Handling
Operations that can be performed on strings, such as finding the length, extracting substrings, concatenation, and converting between upper and lower case
ASCII Conversion
Converting between character and ASCII code
File Handling - Reading Lines
file1 = open("Customers.txt")
while NOT file1.endOfFile()
print(file1.readLine())
endwhile
file1.close()
File Handling - Writing to a (New) File
newFile("paint.txt")
file2 = open("paint.txt")
paint = input("Enter a paint colour:")
file.writeLine(paint)
file2.close()
Arrays
Declaring and assigning values to 1D and 2D arrays
Flowcharts
A flowchart can be used to visually represent an algorithm. It is more likely you will need to be able to interpret a flowchart rather than draw one.
Flowchart symbols
Algorithm
Input/Output
Process
Decision
Connector
Terminator
Flowchart algorithm
Flowchart diagram representing the same algorithm as the pseudocode
Trace tables
Used to track the value of variables as a program is run. Each row in the trace table represents another iteration, and each column stores the value of a variable as it changes.
Decomposition
Decomposition allows large teams to each take a part of a problem and work on it.
Decomposition allows seemingly impossible problems to be solved by splitting them into simple tasks.
Structure diagrams
Structure charts are used to visually represent breaking a large problem down into the smaller parts that make it up.
Each box represents a smaller problem to be solved.
Lines show which bigger problem the box is a part of.
Linear search
The most simple search algorithm
Each data item is searched in order from the first value to the last as if they were all laid out in a line.
The list does not have to be in any order before it is searched.
Also known as a sequential search.
For large lists, linear search is not very efficient
Binary search
A much more efficient searching algorithm
searches through fewer data and is often much quicker, especially for large data sets.
The list of data must already be sorted in order before a binary search can take place.
Merge sort
A sorting algorithm based on the idea of 'divide and conquer'.
Divides a list into half, again and again until each data item is separate.
Then the items are combined in the same way as they were divided, but now in the correct order.
When the individual lists are all merged together as one list again, then the data is in order and the algorithm will end.
Bubble sort
An algorithm based on the comparison of adjacent data elements.
Data elements are swapped if they are not in the correct order.
Not suitable for large sets of data.
Insertion sort
The list is logically split into sorted values (on the left) and unsorted values (on the right).
Starting from the left, values from the unsorted part are checked and inserted at the correct position in the sorted part.
This continues through all elements of the list until the last item is reached, and sorted.
Insertion sorts are efficient for small data sets but would be slow to sort large sets, compared to alternatives such as a merge sort
Algorithmic thinking
A way of getting to a solution by identifying the individual steps that are needed, creating a set of rules called an algorithm that if followed precisely leads to an answer
Algorithmic thinking
Allows solutions to be automated
Algorithmic thinking involves breaking down a problem, identifying the important data, and creating a step-by-step solution that can be automated