OCR · GCSE Computer Science · J277 · Paper 2 · Specification 2.1

CS8 · Computational thinking and algorithmsPLC WordPLC PDF

Go to mind map

Explain systems and solve computing problems. The 30 quick questions support recall and application; practise full algorithms, programs and evaluations using the PLC tasks.

Revise the key ideas

Computational thinking

  • Decomposition — A quiz application can separate loading questions, collecting answers, marking and reporting scores. Each part can be developed and tested, then connected. Define the interfaces and required information so the pieces solve the original problem together.
  • Abstraction — A route model may keep locations and connections while omitting building colours. What is relevant depends on the purpose: accessibility planning may need slope and step information. Abstraction simplifies a model without removing information essential to the problem.
  • Algorithmic thinking — An algorithm gives an unambiguous procedure, including decisions and repetition when necessary. Specify how valid input becomes output and when processing stops. A wish such as 'find the best score' needs an actual method, not just a restatement of the goal.

Designing and tracing

  • Inputs processes outputs — For a ticket cost, inputs could be ticket count and unit price; processing multiplies them; output is total cost. Include constraints such as a non-negative count. A clear specification helps distinguish correct behaviour from merely producing some output.
  • Structure diagrams — A structure diagram breaks a task into modules, such as booking, payment and confirmation. Lines show their structural connections. It is different from a flowchart, which represents the order and decisions within a procedure.
  • Pseudocode and flowcharts — Pseudocode expresses operations in a readable programming-like form. Flowcharts use start/end symbols, input/output parallelograms, process rectangles and decision diamonds with labelled branches. Directional arrows must make the next step and any loop unambiguous.
  • Selection and iteration — A decision chooses a path based on a condition. A loop repeats a body while or until a condition, or for a specified count. Test whether the condition is checked before or after the body: that affects whether the body can run zero times.
  • Trace tables — A trace table tracks variables, conditions and outputs in execution order. For total = 0 and adding 2, 4, 6, successive totals are 2, 6, 12. Follow the actual assignments rather than guessing from the intended purpose.
    Python accumulator trace
    total = 0
    for value in [2, 4, 6]:
        total = total + value
        print(total)

    Outputs 2, then 6, then 12. Trace total after each assignment.

  • Tracing a branch — If score = 7 and the condition score >= 10 is false, execute the alternative branch. A later instruction outside the branch still executes. Record outputs exactly as produced, including when no output occurs.
  • Correcting algorithms — An algorithm starting maximum at 0 fails on a non-empty list of all negative numbers. Initialising it to the first element and then comparing remaining items fixes that case. Explain the cause, corrected step and retest; do not change code only to match one example.
  • Refining requirements — Clarify whether a list can be empty, whether equal values are allowed and how a search reports failure. Check loop limits so each intended element is processed once. An algorithm that works only for an unstated narrow example is not a complete solution.

Searching

  • Linear search — Linear search compares the target with each item in turn. It works on unsorted data and can stop when a match is found. If no match exists, it may inspect the whole list. Keep the returned position or failure value separate from the target value.
    Python linear search
    def linear_search(values, target):
        for index in range(len(values)):
            if values[index] == target:
                return index
        return -1
    
    print(linear_search([9, 3, 7, 1], 7))

    Outputs 2. Return -1 is the explicitly chosen not-found result.

  • Linear-search example — To find 7 in [9, 3, 7, 1], compare 9 then 3 then 7: three comparisons find the match at zero-based index 2. If searching for 8, all four fail. Index 2 is the third item, not the value 2.
  • Binary search — Binary search requires ordered data. Compare the target with the middle item; if smaller search the lower half, if larger the upper half, and if equal stop. Continue until found or the interval is empty. Sorting first has a cost if the data are not already ordered.
    Python binary search
    def binary_search(values, target):
        low = 0
        high = len(values) - 1
        while low <= high:
            middle = (low + high) // 2
            if values[middle] == target:
                return middle
            if values[middle] < target:
                low = middle + 1
            else:
                high = middle - 1
        return -1
    
    print(binary_search([2, 5, 8, 11, 14, 17, 20], 17))

    Outputs 5, the zero-based index. The list must be ascending; empty lists return -1.

  • Binary-search example — For [2, 5, 8, 11, 14, 17, 20], middle 11 is below target 17, so keep the upper half [14, 17, 20]. Its middle is 17, finding it in two comparisons. Specify how an even-sized interval chooses its middle when tracing.
    Binary search for 17
    Use the labels alongside the associated explanation.
  • Choosing a search — A short unsorted list may suit linear search. A large already sorted list queried frequently benefits from binary search's repeated halving. Describe the method and constraints rather than asserting binary search is always best for every data set.

Sorting

  • Bubble sort — An ascending bubble sort passes along the list comparing adjacent items. Larger items move towards the end. Repeated passes complete the order; a pass with no swaps can terminate early. Do not swap non-adjacent elements and call it a bubble-sort step.
    Python bubble-sort recognition
    def bubble_sort(values):
        result = values.copy()
        for end in range(len(result) - 1, 0, -1):
            swapped = False
            for i in range(end):
                if result[i] > result[i + 1]:
                    result[i], result[i + 1] = result[i + 1], result[i]
                    swapped = True
            if not swapped:
                break
        return result
    
    print(bubble_sort([5, 2, 4, 1]))

    Outputs [1, 2, 4, 5]. Identify adjacent comparisons, the shrinking end and early termination; memorising this code is not required.

  • Bubble-sort trace — For [5, 2, 4, 1], compare 5 and 2 to get [2, 5, 4, 1], then 5 and 4 to get [2, 4, 5, 1], then 5 and 1 to get [2, 4, 1, 5]. The largest is placed but further passes are needed.
  • Insertion sort — Treat the first item as a sorted prefix. Take the next item and shift larger prefix items to make its correct place, then extend the prefix. For [4, 2, 3], inserting 2 gives [2, 4, 3], then inserting 3 gives [2, 3, 4].
    Python insertion-sort recognition
    def insertion_sort(values):
        result = values.copy()
        for i in range(1, len(result)):
            item = result[i]
            j = i - 1
            while j >= 0 and result[j] > item:
                result[j + 1] = result[j]
                j = j - 1
            result[j + 1] = item
        return result
    
    print(insertion_sort([4, 2, 3]))

    Outputs [2, 3, 4]. Trace the sorted prefix and shifted items; memorising this code is not required.

  • Merge sort — Divide the list into smaller parts until individual items remain, then merge ordered parts by repeatedly taking the smaller front item. Merge [2, 7] and [3, 5] as [2, 3, 5, 7]. The comparison is between the current fronts, not arbitrary pairs.
    Python merge-sort recognition
    def merge_sort(values):
        if len(values) <= 1:
            return values.copy()
        middle = len(values) // 2
        left = merge_sort(values[:middle])
        right = merge_sort(values[middle:])
        result = []
        i = 0
        j = 0
        while i < len(left) and j < len(right):
            if left[i] <= right[j]:
                result.append(left[i])
                i = i + 1
            else:
                result.append(right[j])
                j = j + 1
        return result + left[i:] + right[j:]
    
    print(merge_sort([7, 2, 5, 3]))

    Outputs [2, 3, 5, 7]. Recursive calls divide the list; merge chooses from ordered fronts. Recognise the stages rather than memorising recursion.

  • Comparing sorts — Bubble and insertion sorts are straightforward to trace; insertion can work well on nearly ordered lists. Merge sort's divide-and-merge approach suits larger data sets but needs additional working storage in common implementations. J277 requires understanding and applying the named methods, not formal complexity notation.
  • Algorithm practice — Design a largest-value or validated-total algorithm, trace normal and boundary inputs, then correct a deliberate error. Use OCR Exam Reference Language or a familiar high-level language for code-writing tasks. Quick answers support this work but cannot replace constructing and checking a whole algorithm.

Test yourself

30 questions · Random sets of 10. These quick checks support revision; practise longer explanations and justified judgements too.

Mind map

Use the branches to recall the ideas and explain their connections. Check the revision notes for the full detail.

CS8 · Thinking / Design 1 / Design 2 / Search 1

View CS8 · Thinking / Design 1 / Design 2 / Search 1 mind map
CS8 CS8 · Thinking / Design 1 / Design 2 / Search 1 mind map: Thinking, Design 1, Design 2, Search 1. A text version follows.
Open the full-size map to zoom. Download the PDF to print on A4 or enlarge to A3.

Open full-size map Download A4 PDF

CS8 · Search 2 / Sort 1 / Sort 2

View CS8 · Search 2 / Sort 1 / Sort 2 mind map
CS8 CS8 · Search 2 / Sort 1 / Sort 2 mind map: Search 2, Sort 1, Sort 2. A text version follows.
Open the full-size map to zoom. Download the PDF to print on A4 or enlarge to A3.

Open full-size map Download A4 PDF

Read the mind map as text

Thinking

  • Decomposition: Split a problem into manageable subproblems
  • Abstraction: Keep relevant details and omit distractions
  • Algorithmic thinking: Develop precise ordered steps to solve the problem

Design 1

  • Inputs processes outputs: Define the information flow before coding
  • Structure diagrams: Show subdivisions and their relationships
  • Pseudocode and flowcharts: Represent a procedure clearly
  • Selection and iteration: Branch on conditions and repeat appropriately

Design 2

  • Trace tables: Record values as instructions execute
  • Tracing a branch: Only the selected path executes
  • Correcting algorithms: Use counterexamples to locate a defect
  • Refining requirements: Handle boundaries empty cases and termination

Search 1

  • Linear search: Check items one by one until found or exhausted
  • Linear-search example: Searching an unsorted list follows its order
  • Binary search: Repeatedly halve a sorted search interval
  • Binary-search example: Discard the half that cannot contain the target

Search 2

  • Choosing a search: Order and repeated use matter

Sort 1

  • Bubble sort: Compare neighbours and swap out-of-order pairs
  • Bubble-sort trace: One pass does not necessarily finish sorting
  • Insertion sort: Insert the next item into a sorted prefix
  • Merge sort: Split then merge ordered parts

Sort 2

  • Comparing sorts: Explain operations and suitability
  • Algorithm practice: Design trace correct and refine a complete solution

Connections

  • Thinking → Design 1: Decomposition and abstraction help specify precise procedures.
  • Design 2 → Search 1: Tracing and edge-case review check whether a search follows its intended steps.

Part connections

  • CS8 · Thinking / Design 1 / Design 2 / Search 1: Thinking → Design 1 — Decomposition and abstraction help specify precise procedures.
  • CS8 · Thinking / Design 1 / Design 2 / Search 1: Design 2 → Search 1 — Tracing and edge-case review check whether a search follows its intended steps.
  • CS8 · Search 2 / Sort 1 / Sort 2: Search 2 → Sort 1 — Binary search requires sorted data; sorting creates that ordering.
  • CS8 · Search 2 / Sort 1 / Sort 2: Sort 1 → Sort 2 — Sorting methods move items differently while producing the same ordered result.