AS and A Level OCR AS/A Level Computer Science
Programming techniques (2.2.1)
Navigate to resources by choosing units within one of the unit groups shown below.
Introduction
Overview
Delivery guides are designed to represent a body of knowledge about teaching a particular topic and contain:
- Content: A clear outline of the content covered by the delivery guide;
- Thinking Conceptually: Expert guidance on the key concepts involved, common difficulties students may have, approaches to teaching that can help students understand these concepts and how this topic links conceptually to other areas of the subject;
- Thinking Contextually: A range of suggested teaching activities using a variety of themes so that different activities can be selected which best suit particular classes, learning styles or teaching approaches.
Curriculum content
Overview
Content (from A-level)
Software programs exist to solve problems. So, programming is a highly structured way of problem solving. Students should develop the ability to:
Break the problem down into smaller manageable chunks and understand how these interact
Plan the program before coding it using pseudocode and flowcharts
Visualise the flow of data and understand its types, as well as the process of user interaction with the program
Be aware of the facilities of the chosen language and how well they match the problem at hand
Create efficient code without logical or syntax errors
Be aware of the facilities of the chosen IDE to debug and construct interfaces
2.2.1 Programming techniques
a) Programming constructs: sequence, iteration, branching.
b) Recursion, how it can be used and compares to an iterative approach.
c) Global and local variables.
d) Modularity, functions and procedures, parameter passing by value and by reference.
e) Use of an IDE to develop/debug a program.
f ) Use of object-oriented techniques.
a) Programming constructs: sequence, iteration, branching.
How to Think Like a Computer Scientist:
Learning with Python: Interactive Edition 2.0 (the Runestone Interactive Project at Luther College, led by Brad Miller and David Ranum, based on the original work by: Jeffrey Elkner, Allen B. Downey and Chris Meyers) –
Link 2 and specifically:
Think Python textbook: An interactive online textbook that uses Python to illustrate programming concepts. It has interactive code but is also available as a PDF. The original book is available on Amazon and direct from the publisher.
Controlling Program Flow in Plain English (John G. McGuinn): Explaining these concepts using everyday actions of making coffee.
MIT Electrical Engineering and Computer Science website provides a good overview but can be a bit dry (but surprisingly accessible).
b) Recursion, how it can be used and compares to an iterative approach.
c) Global and local variables.
d) Modularity, functions and procedures, parameter passing by value and by reference.
e) Use of an IDE to develop/debug a program.
f ) Use of object-oriented techniques.
Thinking conceptually
Overview
Common misconceptions or difficulties students may have
Conceptual links to other areas of the specification – useful ways to approach this topic to set students up for topics later in the course.
The most important technique is the ability to break down a complex task into simple sub-tasks and write (or recycle) selfcontained code in the form of functions and procedures (and classes/objects at the higher end of ability). The code that isn’t made modular becomes quickly overwhelming and leads to endless debugging rather than program improvement, despite having an added benefit of learners becoming familiar with the debugging tools of their IDE.
It is advisable to introduce functions and procedures as early as possible, before branching and iteration. Left too late, modular programming tends to put learners under stress as it requires them to relearn the skills they have just become comfortable with. Teaching learners that we define our routines in one place and trigger them in another place in a program is great for focusing them and reduces the number of blocks they need to track at any one time. While it might be easier to introduce procedures before functions, it is important that learners get a chance to use both, so they can later use the most appropriate ones for the task at hand.
The use of functions requires more planning and confidence in coding and will not come easy to all learners. Objectoriented programming takes modularity to a new level and introduces another layer of variables – object variables. It is important that learners understand that every task can be done either through procedures with global/local variables, or functions with local variables only and parameter passing between the functions, or with objects and it is advisable to ask pupils to produce multiple versions of the same program using all three paradigms.
Sequence, iteration and branching are best introduced through the various validation routines and any mistakes, especially logical mistakes, become obvious quite soon, simplifying the debugging. Nested branching (an if statement inside another if statement) is not trivial but the process of validating input data requires it, e.g., the type check often needs to be performed before range check and needs planning and sequencing of nested branching.
Non-conditional Iteration is best illustrated through lists/ arrays, especially 2d arrays. Being able to generate a times table or read a CSV file are the rights of passage, while conditional Iteration lends itself to validation and user interface duties.
Understanding recursion requires confident knowledge of functions, parameter passing, selection and iteration. In other words, it brings together almost all of the concepts of this section. While recursion can always be replaced by simple iteration, conceptually, it requires more meticulous program planning and hence is a good discriminator in assessment and is also needed for efficient sorting and searching.
Thinking contextually
Activity 1: Branching
Little Man Computer makes heavy use of branching under three conditions: positive accumulator, zero accumulator and always. Branching effectively replaces iteration.
The explanation can be found within the Branching resource.
As LMC doesn’t have a division operator, it has to rely on repeated subtraction and counting how many times one number can be subtracted from another without making the result zero. This is analogous to the main point of division – to find out how many times can we fit one number inside the other.
Task 1: Create a flow chart for dividing 15 into 3 without the use of division.
Task 2: Pretend that your favourite high-level programming language doesn’t have division or multiplication. How would you implement this example?
Task 3: Implement this program in LMC
Task 4: Write out a dry trace table for dividing 15 into 3 (see Learner resource 1.1 for table).
Activity 2: Sorting a nested list
Nested lists can’t be easily sorted by the second column in Python (or most other languages).
Task A: Design a solution that can sort a 2-column nested list alphabetically by the second, not first column.
Save in the same folder as your Python program will be.
Output:
Need to remove the empty last element:
Populate the nested (2d) list n:
Output:
Display the list in tabulated form:
Output:
Activity 3: Iterative vs recursive printing out of a list
Task A: Given a list a=[2,9,6,8,3], develop at least two iterative solutions to print out every item on this list, from the first to the last.
Task B: Given a list a=[2,9,6,8,3], develop at least two iterative solutions to print out every item on this list, from the last to the first.
Task C: Given a list a=[2,9,6,8,3], develop at least one recursive solution to print out every item on this list, from the first to the least and one recursive solution to print out every item from the last to the first.

Acknowledgements
Overview
OCR’s resources are provided to support the teaching of OCR specifications, but in no way constitute an endorsed teaching method that is required by the Board and the decision to use them lies with the individual teacher. Whilst every effort is made to ensure the accuracy of the content, OCR cannot be held responsible for any errors or omissions within these resources. We update our resources on a regular basis, so please check the OCR website to ensure you have the most up to date version.
© OCR 2015 - This resource may be freely copied and distributed, as long as the OCR logo and this message remain intact and OCR is acknowledged as the originator of this work.