Unit 12 Algorithms Teaching Guide
Unit 12 Algorithms Teaching Guide
This unit and all the worksheets, PowerPoint presentations, teaching guides and other
associated files distributed with it are supplied to you by PG Online Limited under licence
and may be used and copied by you only in accordance with the terms of the licence. Except
as expressly permitted by the licence, no part of the materials distributed with this unit may
be used, reproduced, stored in a retrieval system, or transmitted, in any form or by any
means, electronic or otherwise, without the prior written permission of PG Online Limited.
Licence agreement
This is a legal agreement between you, the teaching institution, and PG Online Limited. PG
Online Limited grants to you a non-exclusive, non-transferable, revocable licence to use this
unit and all the worksheets, PowerPoint presentations, teaching guides and other associated
files distributed with it in the course of teaching by your teachers and/or employees.
The materials distributed with this unit may be copied and used by your teachers and/or
employees on a single site only in the course of their teaching. You warrant that you shall
not, and shall procure that each of your teachers and/or employees shall not, share in any
way any of the materials or part of the materials with any third party, including users on
another site or individuals who are teachers and/or employees of a separate institution. You
acknowledge and agree that the materials must remain with you, the teaching institution, and
no part of the materials may be transferred to another institution. You also warrant that you
shall not, and shall procure that each of your teachers and/or employees shall not, procure,
authorise, encourage, facilitate or enable any third party to reproduce these materials in
whole or in part without the prior permission of PG Online Limited.
In consideration of the licence granted to you, you shall indemnify PG Online Limited against
all liabilities, costs, expenses, damages and losses (including but not limited to any direct,
indirect or consequential losses, loss of profit, loss of reputation and all interest, penalties
and legal costs and all other professional costs and expenses) suffered or incurred by PG
Online Limited arising out of or in connection with the exercise by you of your rights granted
under this licence.
Summary
This is a theoretical unit covering Section 2.3 Algorithms (except algorithms for stacks,
queues, trees and linked lists which are covered in Unit 7). Searching and sorting algorithms
(bubble sort, insertion sort, merge sort, quick sort) are explained in an interactive and
practical way, with reference to Big-O notation in terms of time and space complexity. Topic
5 tackles standard algorithms for depth-first and breadth-first graph traversals. Optimisation
algorithms, such as Dijkstra’s shortest path algorithm and the A* algorithm are covered along
with a discussion of intractable problems, in the final topic.
Suggested Resources
No specific software is required for this unit beyond a standard office suite of applications for
the presentation and printing of provided resources.
The textbook OCR AS and A Level Computer Science by PM Heathcote and RSU
Heathcote provides comprehensive coverage of all the theoretical topics in the OCR
specification (H446) and complements the unit series.
Each of the twelve sections in the book corresponds to one of the teaching units in this
series and will be extremely useful as a course textbook and also as a revision guide.
Sample questions, many taken from past exam papers, are included at the end of each
chapter and can be set as additional homework.
The book is published by PG Online in a printed and electronic edition. Please refer to
www.pgonline.co.uk for ordering and pricing details.
Assessment
Assessment will be by means of regular homework and a test with examination style
questions.
Learning Objectives:
• Analyse the suitability of different algorithms for a given task and data set
• Be familiar with measures and methods to determine the efficiency of different
algorithms
• Define constant, linear, polynomial, exponential and logarithmic functions
• Use Big-O notation to compare the time complexity of algorithms
• Be able to derive the time complexity of an algorithm
Content Resources
Big-O notation
Plenary
Go over the answers. Show the final two plenary slides to
recap the lesson. Algorithms Homework 1
Analysis and design of
Hand out Homework 1. algorithms
Algorithms Homework 1
Answers
Preparation:
• The Word documents Girls names (10) and Girls names (20) contain two sets of
girls’ names. You need one set for each student, preferably laminated and cut up in
advance. These will be used in kinaesthetic exercises to manually search and sort a
list.
Learning Objectives:
• Write and trace algorithms for linear search and binary search
• Analyse the time complexity of the linear search and binary search algorithms
• Describe and trace the binary tree search algorithm
Content Resources
Plenary
Go over the answers to Task 2.
Algorithms Homework 2
Give out Homework 2. Searching algorithms
Algorithms Homework 2
Answers
Preparation:
• The Word documents Girls names (10) and Girls names (20) contain two sets of
girls’ names. You need one set for each student, preferably laminated and cut up in
advance. These will be used in kinaesthetic exercises to manually search and sort a
list.
Learning Objectives:
• Be able to describe the bubble sort and insertion sort algorithms
• Be able to trace the bubble sort and insertion sort algorithms
Content Resources
The algorithm for the insertion sort is given – note how the
item being looked at is held temporarily in nextItem, while the
other items are moved right until its correct place is found,
when it is re-inserted into the list.
Ask students to do the questions in Task 2.
There is a Python program insertion sort.py in the Python Insertion sort.py
program folder.
Extension task.
If there is time for practical, students could write a program to
time the bubble sort and insertion sort.
Timing sorts.py
See timing sorts.py in the Python Program folder, which also
includes a merge sort.
Time complexity of insertion sort
Let students work this out – the clue is in the two nested loops.
It is O(n2).
Preparation:
• The Word documents Girls names (10) and Girls names (20) contain two sets of
girls’ names. You need one set for each student, preferably laminated and cut up in
advance. These will be used in kinaesthetic exercises to manually search and sort a
list.
• Go through the animation of the quicksort in the PP slides to make sure you can follow
what is going on and can answer any questions.
Learning Objectives:
• Understand and be able to trace the merge sort and quick sort algorithms
Content Resources
Learning Objectives:
Content Resources
Learning Objectives:
• Understand and be able to trace Dijkstra’s shortest path algorithm
• Be aware of applications of the shortest path algorithm
• Describe the A* algorithm
Content Resources
Limits of computation
Discuss the limits of computation. These are algorithmic complexity (think
Big-O) and hardware.
There is an interesting history of weather forecasting, once considered
incomputable, at http://www-history.mcs.st-
andrews.ac.uk/HistTopics/Weather_forecasts.html
It would be worth students looking at this.
The travelling salesman problem (TSP)
This is a very well-known problem, which has applications in many fields
from planning the optimum route for the school bus run, to the
manufacture of circuit boards.
Students could Google this to read around the subject.
Tractable problems
The A* algorithm
This is a general path-finding algorithm which uses a similar method to
Djikstra’s algorithm but includes a heuristic function as well.
It is used, for example, in logistics and gaming.
Learning Outcomes:
Students will
• apply their knowledge in answers to a range of questions
• be able to highlight areas of strength and any gaps in their understanding of computers
Content Resources
Big-O calculation.py
Big-O calculation.vb
Final assessment
binary search Qu 2c.py
Every effort has been made to trace the copyright holders and we apologise in advance for
any unintentional omissions. We would be pleased to insert the appropriate
acknowledgement in any subsequent edition of this publication.
This material contains links to relevant websites featured in the teacher’s guide. Every effort
has been made to ensure that at the time of distribution, the links remain unbroken, the
material remains up-to-date and that links are not inadvertently linked to sites that could be
considered offensive. PG Online cannot be held responsible for the content of any website
mentioned in this material. It is sometimes possible to find relocated sites by typing the
original URL into a browser. Any errors should be reported directly to
[email protected] and changes will be made in any subsequent editions of the
material.
Artwork