levo

Algorithms

  • 17 subtopics
  • 39 things to know
  • Component 02

What Algorithms covers

Algorithms is examined on component 02 of OCR Computer Science, Algorithms and programming. 230 recall questions across 17 subtopics.

Where it is assessed

Component 02

Algorithms and programming, the whole of the second paper.

Check the OCR specification ↗

The 17 subtopics

Each one has its own page.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

What problem does Dijkstra's algorithm solve, and what does it record?

Process

Give three ways an algorithm can be expressed at the design stage.

Key term

Distinguish between time complexity and space complexity.

Key term

For each of these, state what happens to the running time when n doubles: constant, logarithmic, linear, polynomial of order two, exponential.

Key term

Compare searching a sorted array with searching an unsorted array of the same size.

Key term

Explain how the amount of data you expect changes which algorithm is suitable.

Key term

What is a stack, and what does LIFO mean?

Key term

Describe the algorithm for pushing an item onto a stack.

Key term

Describe the algorithm for popping an item from a stack.

Key term

What is a queue, and what does FIFO mean?

Key term

Describe the algorithm for adding an item to a queue.

Key term

What is a priority queue and how does it differ from an ordinary queue?

Key term

Describe how a linked list is stored.

Key term

How do you traverse a linked list?

Key term

Describe the algorithm for inserting a new node into an ordered linked list.

Key term

Describe the structure of a rooted tree.

Key term

Take a binary search tree with root 50, whose left child is 30 with children 20 and 40, and whose right child is 70 with children 60 and 80. Describe the algorithm for searching it for 60 and count the comparisons.

Key term

In a binary search tree with root 50, children 30 and 70, and leaves 20, 40, 60, 80, what happens searching for 45?

Key term

What does traversing a tree mean, and why is more than one traversal needed?

Key term

Trace a bubble sort on the list 5, 1, 4, 2, showing each pass.

Key term

Trace an insertion sort on the list 5, 1, 4, 2.

Key term

Merge the sorted lists 2, 5, 9 and 1, 6 by hand, showing each comparison.

Key term

Trace a merge sort on the list 6, 3, 8, 1.

Process

A merge sort is applied to a list of 1,024 items. Roughly how does the work compare with a bubble sort on the same list?

Key term

Trace a quick sort on the list 7, 2, 9, 4, 1, taking the first item as the pivot.

Key term

Trace what happens when quick sort with a first-item pivot is applied to the already-sorted list 1, 2, 3, 4.

Key term

Summarise the best, average and worst-case time complexity of bubble, insertion, merge and quick sort.

Key term

Which of the four are stable, and which are not?

Key term

Which sorts benefit from data that is already nearly in order, and which do not care?

Key term

Describe the linear search algorithm.

Key term

Trace a linear search for 7 in the list 4, 9, 2, 7, 5 and count the comparisons.

Key term

Trace a linear search for 6 in the list 4, 9, 2, 7, 5.

Key term

Describe the binary search algorithm.

Key term

Trace a binary search for 19 in the list 3, 7, 11, 15, 19, 23, 29.

Key term

A sorted list has an even number of items so there is no exact middle. Does this break the algorithm?

Key term

Define g, h and f as A* uses them.

Who and when

S joins A with weight 2 and B with weight 2. A joins the goal G with weight 6. B joins C with weight 1, and C joins G with weight 1. The straight-line estimates to G are 3 from S, 5 from A, 2 from B, 1 from C and 0 at G. A* run from S finds the route S, B, C, G. Which node did A* never expand, and what would Dijkstra's algorithm have done?

Key term

For the graph S–A 2, S–B 2, A–G 6, B–C 1, C–G 1 with heuristics 3, 5, 2, 1, 0, verify the heuristic is admissible.

Key term

Give the pre-order traversal of the binary search tree with root 50, children 30 and 70, and leaves 20, 40, 60 and 80.

Take Algorithms further

The same content, four other ways.

Commonly confused

Pairs that lose marks when they are blurred together.

  • Time complexity vs Space complexity

    Time complexity: how the running time of an algorithm grows as its input grows. Space complexity: how much additional memory an algorithm needs as its input grows.

  • A static stack vs A dynamic stack

    A static stack: a structure of fixed size, decided when it is created and never changed. A dynamic stack: a structure that grows and shrinks as items are added and removed.

  • A breadth-first traversal vs A depth-first traversal

    A breadth-first traversal: a traversal visiting every node at one distance before going any deeper. A depth-first traversal: a traversal following one path as far as it goes before backing up.

Questions from this topic

Each one with the model answer underneath.

  1. 1

    What is an algorithm?

    Model answer

    A finite sequence of unambiguous steps that takes some input, carries out a defined process and produces an output, solving a problem or completing a task. It must be precise enough that it can be followed without judgement, and it must terminate rather than run forever.

  2. 2

    A student says 'my program is my algorithm'. Why is that not quite right?

    Model answer

    An algorithm is the method itself, independent of any language. A program is one implementation of it. The same algorithm can be written in Python, in pseudocode, as a flowchart or in structured English, and it is still the same algorithm, so the method can be analysed and compared before a single line of code is written.

  3. 3

    What are the first things you should establish when analysing a problem before designing an algorithm?

    Model answer

    What the inputs are and where they come from, what output is required and in what form, what processing turns one into the other, what data will be stored and in what structure, and what constraints apply such as how much data there will be, how fast it must run and how much memory is available.

  4. 4

    Explain how decomposition helps in the design of an algorithm.

    Model answer

    Decomposition breaks a large problem into smaller sub-problems, each of which can be solved, tested and understood separately. It makes the design manageable, allows different sub-problems to be worked on independently or reused elsewhere, and means a fault can be located in one small part rather than across the whole solution.

  5. 5

    What is a pre-condition, and why should an algorithm's design state it?

    Model answer

    A pre-condition is something that must be true before the algorithm is run for it to work correctly, for example that the list is already sorted or that the input value is positive. Stating it makes clear whose responsibility the check is, and prevents the algorithm being used in a situation where it will silently give a wrong answer.

  6. 6

    Give three ways an algorithm can be expressed at the design stage.

    Model answer

    Structured English, pseudocode, and a flowchart. All three express the same logic; the choice is about who has to read it. Pseudocode is close enough to code to translate directly, a flowchart makes the flow of control visible, and structured English is easiest for a non-programmer to check.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

A0 + 0 gives 0.
B0 + 1 gives 1.
C1 + 1 gives 0 carry 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

A global variable means a variable reachable from anywhere in the program.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Algorithms revision questions

What does Algorithms cover in OCR A-Level Computer Science?
17 subtopics: designing and analysing an algorithm, measuring efficiency and big o notation, comparing algorithms and choosing one for a task, stacks, queues, linked lists, trees and binary search trees, traversing a tree: depth-first and breadth-first, bubble sort, insertion sort, merge sort, quick sort, comparing the four sorting algorithms, linear search, binary search, dijkstra's shortest path algorithm and the a* algorithm. Each one has its own page with questions and model answers.
How is Algorithms organised?
By the OCR H446 specification, subtopic by subtopic, so it matches the order you are taught it in.

Every question in Algorithms, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.