![]() |
| Photo by ThisIsEngineering on Pexels |
If you take OCR GCSE Computer Science, half your grade comes from a paper that asks you to think like a programmer: Component 02, Computational Thinking, Algorithms and Programming. This article gives you 20 OCR GCSE Computer Science J277 programming algorithms MCQs with answers and explanations, so you can test the exact skills the paper rewards — designing algorithms, tracing pseudocode, writing Python, spotting errors and reasoning about logic gates. It is the paper where marks come from doing, not just knowing: reading code, following it line by line, and saying what it outputs.
This article gives you 20 original OCR GCSE Computer Science J277 programming algorithms MCQs with full explanations, mapped to topics 2.1–2.5 of the Component 02 specification. Each topic starts with a short revision note, and every Python snippet in the bank was actually run — the outputs stated are the real outputs, not guesses. Work through the bank, read every explanation, and use the score guide at the end to plan what to revise next.
How Component 02 fits the qualification
OCR GCSE Computer Science J277 has two written papers, each worth 50% of the qualification. J277/02 — Computational thinking, algorithms and programming — is a written paper of 1 hour 30 minutes and 80 marks, assessing topics 2.1–2.5. Calculators are not allowed. It has two sections: Section A is worth 50 marks and tests your knowledge and understanding of the concepts, applied to problems in computational terms; Section B is worth 30 marks and tests your practical programming skills — designing, writing, testing and refining programs. All questions are mandatory, and in Section B, questions that ask you to write or refine algorithms must be answered using the OCR Exam Reference Language — OCR's own pseudocode. The companion paper, J277/01 Computer systems, is also 1 hour 30 minutes and 80 marks; see our OCR computer systems MCQs for that half of the course.
Component 02 has five topics: 2.1 Algorithms (computational thinking, searching and sorting), 2.2 Programming fundamentals (variables, data types, selection, iteration, arrays, subprograms, files, SQL), 2.3 Producing robust programs (defensive design, validation, testing), 2.4 Boolean logic (AND, OR, NOT, truth tables, logic circuits) and 2.5 Programming languages and Integrated Development Environments (translators and IDEs). This bank covers all five, matching its title; data representation — binary, hexadecimal, images, sound and compression — sits in Paper 1 (topic 1.2, Memory and storage), and the FAQ at the end says where it fits.
Revision notes — learn these before the questions
2.1 Algorithms
Computational thinking is three skills. Abstraction means removing unnecessary detail and keeping only what matters for the problem. Decomposition means breaking a big problem into smaller parts that are easier to solve. Algorithmic thinking means writing a clear, step-by-step set of instructions that solves the problem — an algorithm.
Algorithms are written as pseudocode, flowcharts or high-level code. A trace table follows a program line by line, writing down how each variable changes — it is how you find out what a program really does, and the exam loves trace-table questions. Debugging is finding and fixing errors in a program.
Searching. Linear search checks each item in turn, from the first to the last, until it finds the target. It works on unsorted lists, but it is slow on long ones — in the worst case it checks every item. Binary search only works on a sorted list: it looks at the middle item, and if the target is smaller it searches the left half, if larger the right half, halving the list each time. On a list of 15 items it needs at most 4 comparisons; on a list of 1,000 it needs at most 10. That is why the exam asks you which search to use, not just how each one works.
Sorting. Bubble sort repeatedly goes through the list swapping adjacent items that are in the wrong order; after each pass, the largest unsorted item has "bubbled" to the end. Merge sort splits the list in half again and again until each piece has one item, then merges the pieces back together in order — a divide and conquer approach that is much faster than bubble sort on long lists. Insertion sort builds the sorted list one item at a time, inserting each new item into its correct place among the items already sorted.
The OCR pseudocode you must be able to read
Section B uses the OCR Exam Reference Language. You do not have to memorise it perfectly — the exam gives you the conventions — but you must be able to read it. The rules that matter:
- Assignment uses
=, and comparison uses==. Sototal = 0sets total to zero, whileif total == 0 thentests whether total is zero. Mixing them up is the single most common pseudocode mistake. - Input and output:
name = input("Please enter your name")reads a value;print("hello")writes to the screen. - Count-controlled loop:
for i = 0 to 7...next iruns 8 times (0 to 7 inclusive). - Condition-controlled loops:
while answer != "computer"...endwhilechecks the condition before each run;do...until answer == "computer"checks it after, so it always runs at least once. - Selection:
if ... then...elseif ... then...else...endif. OCR also allowsswitch/case. - Subroutines:
function triple(number)...return number * 3...endfunctionreturns a value;procedure greeting(name)...endproceduredoes not. Unless stated otherwise, values are passed by value. - Arrays are 0-based and declared with the keyword
array:array names[5], thennames[0] = "Ahmad". A two-dimensional array is declared asarray board[8, 8]. - Boolean operators are written as words:
AND,OR,NOT— for examplewhile x <= 5 AND flag == false.
Photo by Startup Stock Photos on Pexels
2.2 Programming fundamentals
Variables hold data that can change; constants hold data that cannot (such as the value of pi, or a fixed VAT rate). Data types in OCR J277 are integer (whole number), real (number with a decimal part), Boolean (true or false), character (a single character) and string (zero or more characters). Casting changes a value from one type to another — for example, turning the string "7" into the integer 7 so you can do maths with it.
Operators. Arithmetic: + - * / MOD (remainder) DIV (whole-number division) ^ (power). Comparison: == != < > <= >=. Boolean: AND OR NOT. The three program constructs are sequence (one step after another), selection (if/else, switch/case) and iteration — count-controlled (for loops, when you know how many times) and condition-controlled (while and do...until, when you stop on a condition).
Strings. You can join strings with + (concatenation), find a string's length, take a substring, and change case. In OCR pseudocode and in Python, the first character is at index 0.
Arrays and records. A one-dimensional array holds a list of values of the same type; a two-dimensional array holds a grid (rows and columns). A record groups different types of data about one thing — for example, a student record with a name (string), an age (integer) and a grade (character). SQL is the language for querying a database: SELECT name FROM students WHERE grade = 'A' returns the names of students with grade A. Subprograms keep code tidy: a function returns a value, a procedure does not; both take parameters, and parameters are passed by value unless the question says byRef. Random number generation produces a random value in a range — used in games and simulations. File handling means opening a file, reading from or writing to it, and closing it again; endOfFile() tells you when you have reached the end.
2.3 Producing robust programs
Defensive design means writing a program that does not break when the user does something unexpected. Input validation checks data as it is entered: a range check (is the mark between 0 and 100?), a length check (is the password at least 8 characters?), a presence check (has anything been entered at all?), a format check (does the email contain an @?) and a type check (is this a number, not text?). Authentication checks that the user is who they claim to be — a password or PIN. Maintainability is writing code other people (including future you) can understand: meaningful variable names, comments, and sensible indentation.
Testing. Iterative testing means testing as you write, fixing problems as you find them; final (terminal) testing means testing the finished program. Three kinds of test data: normal data (valid, everyday values), boundary data (values at the very edge of the valid range, such as 0 and 100 for a mark out of 100) and erroneous data (invalid values, such as −5 or "abc" for a mark — the program should reject them). Syntax errors break the rules of the language — the program will not run at all, and the compiler or interpreter finds them. Logic errors are worse: the program runs, but it does the wrong thing (for example, adding when it should subtract). Runtime errors crash the program while it is running, such as dividing by zero.
2.4 Boolean logic
There are three operators to learn, with their truth tables:
| A | B | A AND B | A OR B | NOT A |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
AND gives 1 only when both inputs are 1. OR gives 1 when at least one input is 1. NOT flips the input: 1 becomes 0, 0 becomes 1. A logic circuit combines gates to carry out a job — for example, a burglar alarm that sounds when the sensor is triggered AND the system is armed. The exam asks you to complete truth tables, draw circuits from expressions, and work out the output of an expression step by step. Work from the inside out, brackets first, just like in maths.
2.5 Programming languages and Integrated Development Environments
Machine code is binary — the only language the CPU understands directly. Assembly language uses short mnemonics such as ADD and MOV instead of binary, one assembly instruction for each machine-code instruction. High-level languages (Python, Java, C#) use English-like words; one high-level statement becomes many machine-code instructions.
A program written in a high-level language must be translated before the CPU can run it. A compiler translates the whole program into machine code before it runs, producing an executable file, and reports all the errors at once. An interpreter translates and runs the program line by line, stopping at the first error it meets — slower, but easier to debug. An assembler translates assembly language into machine code. A low-level language is close to the hardware (machine code, assembly); a high-level language is close to human language.
An Integrated Development Environment (IDE) is the software programmers write code in. Its features include a code editor with syntax highlighting, auto-completion of keywords, error diagnostics that flag mistakes as you type, a debugger that lets you pause a program, step through it line by line and inspect variables, and tools to run and test the program without leaving the editor.
Questions 1–20: OCR GCSE Computer Science J277 programming and algorithms MCQs
Q1. Which of these is the best definition of abstraction?
A. Removing unnecessary detail and keeping only what matters for the problem
B. Breaking a problem into smaller parts
C. Writing instructions in a step-by-step order
D. Repeating a set of instructions until a condition is met
Answer: A — Removing unnecessary detail and keeping only what matters for the problem. Abstraction is deliberately ignoring the details that do not matter, so you can focus on the important ones — a map shows roads, not every tree. Breaking a problem into smaller parts (B) is decomposition, step-by-step instructions (C) describe an algorithm, and repeating instructions (D) is iteration.
Q2. A binary search is used on a sorted list of 15 items. What is the greatest number of comparisons needed to find an item (or confirm it is not there)?
A. 3
B. 4
C. 5
D. 15
Answer: B — 4. Binary search halves the list each time: 15 items → 7 → 3 → 1, which is 4 comparisons. That is the worst case — if the target is the middle item, it is found in one. Option D (15) is the worst case for a linear search, which checks every item in turn. Binary search only works because the list is sorted.
Q3. What does this OCR pseudocode output?
total = 0
for i = 1 to 4
total = total + i
next i
print(total)
A. 6
B. 8
C. 10
D. 12
Answer: C — 10. Trace it: i = 1 → total = 1; i = 2 → total = 3; i = 3 → total = 6; i = 4 → total = 10. The loop runs four times (1 to 4 inclusive), adding 1 + 2 + 3 + 4 = 10. Option A (6) is the total after three passes — the classic mistake is stopping the loop one step early.
Q4. Which sorting algorithm repeatedly compares adjacent items and swaps them if they are in the wrong order?
A. Merge sort
B. Bubble sort
C. Insertion sort
D. Linear sort
Answer: B — Bubble sort. Bubble sort walks along the list comparing neighbours and swapping any pair that is out of order; after each pass the largest unsorted item has "bubbled" to the end. Merge sort (A) splits the list in half and merges the halves back in order. Insertion sort (C) takes each item and inserts it into its correct place in the sorted section. There is no sorting algorithm called "linear sort" (D) — linear is a search, not a sort.
Q5. After the first complete pass of a bubble sort (ascending), what is the order of the list [5, 2, 9, 1]?
A. [2, 5, 1, 9]
B. [1, 2, 5, 9]
C. [5, 2, 1, 9]
D. [2, 1, 5, 9]
Answer: A — [2, 5, 1, 9]. Walk through it: compare 5 and 2 → swap → [2, 5, 9, 1]; compare 5 and 9 → no swap; compare 9 and 1 → swap → [2, 5, 1, 9]. One pass only moves the largest item (9) to the end — the list is not fully sorted yet (B is the finished list, after three passes). If you picked B, you ran the whole sort instead of one pass.
Q6. What does this Python program output?
total = 0
for i in range(1, 6):
total = total + i
print(total)
A. 10
B. 15
C. 20
D. 21
Answer: B — 15. range(1, 6) gives 1, 2, 3, 4, 5 — the end value is not included. So total = 1 + 2 + 3 + 4 + 5 = 15. (Run in Python 3.12.3: output 15.) Option A (10) is the sum of 1 to 4, and option D (21) is the sum of 1 to 6 — both come from misreading the range.
Photo by Gerald Venzl on Pexels
Q7. What does this Python program output?
grid = [[4, 7], [9, 2]]
print(grid[1][0] + grid[0][1])
A. 11
B. 13
C. 16
D. 18
Answer: C — 16. This is a two-dimensional array — a grid of rows and columns. grid[1][0] is row 1, column 0, which is 9; grid[0][1] is row 0, column 1, which is 7. So 9 + 7 = 16. (Run in Python 3.12.3: output 16.) Remember that both rows and columns are numbered from 0, and the first index is the row, the second is the column.
Q8. What does this Python program output?
word = "Python"
print(word[0] + word[-1])
A. "Py"
B. "Pn"
C. "on"
D. "Po"
Answer: B — "Pn". word[0] is the first character, "P", and word[-1] is the last character, "n" — in Python, a negative index counts back from the end. So the program prints "Pn". (Run in Python 3.12.3: output Pn.) Option A ("Py") is the first two characters, and option C ("on") is the last two.
Q9. What does this Python program output?
score = 72
if score >= 80:
grade = "A"
elif score >= 60:
grade = "B"
else:
grade = "C"
print(grade)
A. "A"
B. "C"
C. "B"
D. "D"
Answer: C — "B". The first test fails (72 is not ≥ 80), so Python checks the second: 72 ≥ 60 is true, so grade becomes "B" and the else is skipped. (Run in Python 3.12.3: output B.) This is selection with elif — each condition is only tested if the ones before it failed.
Q10. What does this Python program output?
def double(n):
return n * 2
print(double(3) + double(4))
A. 12
B. 14
C. 16
D. 24
Answer: B — 14. double is a function — a subprogram that returns a value. double(3) returns 6 and double(4) returns 8, so 6 + 8 = 14. (Run in Python 3.12.3: output 14.) A function is different from a procedure: a function returns a value to the program that called it, a procedure does not.
Q11. What does this Python program output?
x = 1
while x < 8:
x = x * 2
print(x)
A. 7
B. 16
C. 8
D. 4
Answer: C — 8. Trace it: x starts at 1. 1 < 8, so x becomes 2. 2 < 8, so x becomes 4. 4 < 8, so x becomes 8. Now 8 < 8 is false, so the loop stops and the program prints 8. (Run in Python 3.12.3: output 8.) This is a condition-controlled loop — it runs until the condition fails, and the number of runs is not fixed in advance.
Q12. In OCR pseudocode, what are the values of 17 DIV 4 and 17 MOD 4?
A. 4 and 1
B. 4 and 3
C. 3 and 1
D. 4 and 4
Answer: A — 4 and 1. DIV is whole-number division: 17 ÷ 4 = 4 remainder 1, so 17 DIV 4 = 4. MOD gives the remainder: 17 MOD 4 = 1. (Run in Python 3.12.3: 17 // 4 is 4 and 17 % 4 is 1.) Option B (4 and 3) is the common slip — 3 is the remainder of 15 ÷ 4, not 17 ÷ 4. Always work out the remainder properly: 4 × 4 = 16, and 17 − 16 = 1.
Q13. A test uses a mark of −5 for a test scored out of 100. What kind of test data is this?
A. Normal data
B. Boundary data
C. Erroneous data
D. Iterative data
Answer: C — Erroneous data. Erroneous data is invalid data that lies outside the acceptable range — a mark of −5 cannot exist, so the program should reject it. Normal data (A) is valid, everyday input such as 72. Boundary data (B) sits at the very edge of the valid range, such as 0 or 100. "Iterative" (D) describes testing done during development, not a kind of test data.
Q14. A program checks that a password is at least 8 characters long before accepting it. What is this an example of?
A. Verification
B. Validation
C. Authentication
D. Compilation
Answer: B — Validation. Validation checks that input data is sensible and reasonable before the program uses it — here, a length check. Verification (A) is different: it checks that data was entered correctly, usually by asking the user to type it twice. Authentication (C) checks that the user is who they claim to be (the password itself, not its length). Compilation (D) is translating a program into machine code.
Q15. A program runs to the end without crashing, but it prints the wrong answer. What kind of error is this?
A. Logic error
B. Syntax error
C. Runtime error
D. Validation error
Answer: A — Logic error. A logic error means the program is grammatically correct and runs, but its logic is wrong — it adds when it should subtract, or uses the wrong variable. A syntax error (B) breaks the rules of the language, so the program will not run at all. A runtime error (C) crashes the program while it is running, such as dividing by zero. Logic errors are the hardest to find, because nothing tells you they are there — only testing with known answers reveals them.
Q16. What is the output of A AND B when A = 1 and B = 0?
A. 1
B. 0
C. 2
D. Both 1 and 0
Answer: B — 0. AND gives 1 only when both inputs are 1. Here B is 0, so the output is 0. If you picked A, you were thinking of OR — OR gives 1 when at least one input is 1, so A OR B would be 1 here. The exam often puts AND and OR side by side to catch exactly this confusion.
Q17. What is the value of the Boolean expression (True OR False) AND (NOT False)?
A. Error
B. False
C. True
D. 1
Answer: C — True. Work from the inside out, brackets first. True OR False is True (OR needs only one true input). NOT False is True (NOT flips the value). So the expression becomes True AND True, which is True. (Run in Python 3.12.3: output True.) Option D (1) is tempting — in many languages True is stored as 1 — but the expression's value is the Boolean True, not the number 1.
Q18. In the truth table for A OR B, how many of the four rows give an output of 1?
A. 4
B. 3
C. 2
D. 1
Answer: B — 3. OR gives 1 when at least one input is 1, so the only row that gives 0 is the one where A = 0 and B = 0. The other three rows (0,1), (1,0) and (1,1) all give 1. Compare with AND, which gives 1 in only one row — the (1,1) row. If you can picture both tables, you will not mix them up.
Q19. Which translator converts a whole high-level program into machine code before it runs, and reports all the errors at once?
A. Assembler
B. Interpreter
C. Compiler
D. Debugger
Answer: C — Compiler. A compiler translates the entire program into machine code first, producing an executable file, and lists all the errors it found so you can fix them together. An interpreter (B) translates and runs the program line by line and stops at the first error. An assembler (A) translates assembly language, not high-level code. A debugger (D) is an IDE tool for finding errors — it is not a translator at all.
Q20. What does an assembler do?
A. Translates machine code into assembly language
B. Translates assembly language into machine code
C. Translates a high-level language into assembly language
D. Translates Python code into pseudocode
Answer: B — Translates assembly language into machine code. Assembly language uses mnemonics such as ADD and MOV, one instruction for each machine-code instruction, and the assembler converts those mnemonics into the binary the CPU understands. It works in the opposite direction to option A. High-level languages are translated by compilers and interpreters (C), not by assemblers, and nobody translates Python into pseudocode (D) — pseudocode is a design tool, not a language a translator targets.
Answer key
1 A · 2 B · 3 C · 4 B · 5 A · 6 B · 7 C · 8 B · 9 C · 10 B · 11 C · 12 A · 13 C · 14 B · 15 A · 16 B · 17 C · 18 B · 19 C · 20 B
Score guide — what your score means
- 17–20 — Strong. Move on to the AQA vs Edexcel vs OCR board comparison, then test the same ideas on another board with our AQA programming in Python MCQs.
- 13–16 — Good foundation with gaps. Re-read the explanations for the questions you missed, especially the trace-table questions (Q3, Q6, Q11) — in the exam, one wrong line in a trace costs the whole question.
- 9–12 — Developing. Go back to the revision notes and learn the definitions first: abstraction vs decomposition, linear vs binary search, validation vs verification, syntax vs logic errors. Then re-attempt the bank.
- 0–8 — Starting out. Learn one topic at a time — start with 2.1 (algorithms), then 2.2 (programming fundamentals) — before trying the bank again. Practise tracing short programs on paper; it is the skill the whole paper depends on.
What to revise next
- If algorithms were weaker: practise trace tables on paper — write the variable values after every line, and do not skip steps. Learn the three sorts by doing them on a short list of numbers by hand, and say out loud why binary search needs a sorted list.
- If programming fundamentals were weaker: write the same small programs in Python and in OCR pseudocode, so the two notations stop feeling different. Practise indexing (remember: first item is index 0) and the difference between
=and==. - If robust programs were weaker: for every program you write, ask "what could a user type that would break this?" — then write the validation check for it. Learn the three kinds of test data with one example each.
- If Boolean logic was weaker: write out the three truth tables from memory until you can do it without thinking, then practise combining them — work brackets first, inside out.
- If languages and IDEs were weaker: learn the three translators as a set — compiler (whole program, before running), interpreter (line by line, while running), assembler (assembly to machine code) — and list four features of an IDE.
- Next in the series: OCR computer systems for Component 01, AQA programming in Python for the same ideas on another board, and the board comparison.
- Official sources: the OCR J277 specification at a glance, OCR's J277 past papers and mark schemes and OCR's GCSE pseudocode guide.
Frequently asked questions
Is Paper 2 really 1 hour 30 minutes and 80 marks?
Yes — that is what the official OCR specification says: J277/02 Computational thinking, algorithms and programming is 1 hour 30 minutes and 80 marks, and J277/01 is the same, for a total of 160 marks. Calculators are not allowed in either paper. Some revision websites state 90 marks per paper, but that is AQA 8525, a different board — trust the OCR specification, not the revision site.
What is the difference between Section A and Section B in J277/02?
Section A is worth 50 marks and tests your knowledge and understanding of the concepts — algorithms, programming ideas, Boolean logic, languages and IDEs. Section B is worth 30 marks and tests your practical programming skills: designing, writing, testing and refining programs. In Section B, questions that ask you to write or refine algorithms must be answered using OCR's pseudocode (the Exam Reference Language), not Python or any other language.
Is data representation (binary and hex) in Paper 2?
No. Data representation — binary, hexadecimal, characters, images, sound and compression — is assessed in Component 01 (J277/01), under topic 1.2 (Memory and storage), not in Component 02. The J277 specification (version 3.1, May 2026) moved data representation from Component 2 to Component 1. This bank covers all five Component 02 topics (2.1–2.5); if binary and hex are your weak spot, revise them as part of your Paper 1 preparation — do not skip them, because Paper 1 does ask you to convert between binary and hexadecimal.
What is the difference between validation and verification?
Validation checks that input data is sensible and reasonable — a range check, a length check, a format check. Verification checks that data was entered correctly, usually by asking the user to enter it twice (for example, typing a new password twice). The exam often asks for one of each, so learn one example of each and do not swap them.
How is OCR J277 different from AQA and Edexcel?
All three boards test the same ideas — algorithms, programming, Boolean logic — but the paper structure differs. OCR J277 has two papers of 1 hour 30 minutes and 80 marks each, with Component 02 split into Section A (50 marks) and Section B (30 marks). AQA 8525 has Paper 1 at 2 hours / 90 marks and Paper 2 at 1 hour 45 minutes / 90 marks. Edexcel 1CP2 has Paper 1 at 1 hour 30 minutes / 75 marks and Paper 2 at 2 hours / 75 marks. See the full AQA vs Edexcel vs OCR comparison.
All 20 questions and explanations here are original MissMono study material. All Python snippets were run in Python 3.12.3 on 6 November 2026 and the outputs stated are the actual outputs. OCR and GCSE Computer Science J277 belong to Oxford Cambridge and RSA Examinations; this page is not affiliated with or endorsed by OCR.


