levo

Fundamentals of Algorithms

  • 6 subtopics
  • 14 things to know
  • Paper 1

What Fundamentals of Algorithms covers

Graph and tree traversal, Reverse Polish notation, searching, sorting and Dijkstra's shortest path algorithm, each with the time complexity it is judged by. Examined on Paper 1.

Where it is assessed

Paper 1

The on-screen programming exam, 2 hours 30 minutes and 40% of the A-level.

Check the AQA specification ↗

The 6 subtopics

Each one has its own page.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

Which data structure does each of breadth-first and depth-first search use, and why?

Process

Why does breadth-first search find the shortest path only in an unweighted graph?

Process

Name the three tree-traversal algorithms and state the order in which each deals with a node and its subtrees.

Process

Why are the tree-traversal algorithms naturally written recursively?

Key term

What is Reverse Polish notation?

Evaluation

Why is Reverse Polish notation used?

Process

How many comparisons does a linear search make in the best, average and worst cases?

Evaluation

Compare linear search and binary search.

Process

Explain what happens to the efficiency of a binary tree search when the tree is unbalanced.

Process

What is the best case for a bubble sort, and what condition does it require?

Process

Why is merge sort described as a divide and conquer algorithm?

Process

What is the time complexity of merge sort, and explain where it comes from?

Process

Why can breadth-first search not be used in place of Dijkstra's algorithm on a weighted graph?

Numbers

In a weighted graph, P–Q costs 2, P–R costs 5, Q–R costs 1 and R–S costs 4. Give the shortest distances from P to Q, R and S.

Take Fundamentals of Algorithms further

The same content, four other ways.

Commonly confused

Pairs that lose marks when they are blurred together.

  • Breadth-first search vs Depth-first search

    Breadth-first search: a traversal using a queue to visit nearby vertices first. Depth-first search: a traversal using a stack or recursion to follow one route deeply.

  • Linear search vs Binary search

    Linear search: a sequential inspection that works on unordered data. Binary search: a halving search that requires ordered data.

  • Bubble sort vs Merge sort

    Bubble sort: an adjacent-swap method making repeated passes. Merge sort: a divide-and-conquer method combining ordered sublists.

Questions from this topic

Each one with the model answer underneath.

  1. 1

    What does it mean to traverse a graph?

    Model answer

    To visit every vertex of the graph exactly once, following the edges, in a systematic order defined by the traversal algorithm. Because a graph may contain cycles, the traversal must record which vertices have already been visited so that it does not go round for ever.

  2. 2

    Describe how a breadth-first search works.

    Model answer

    Start at a chosen vertex, mark it as visited and add it to a queue. Then repeatedly take the vertex at the front of the queue, examine each of its neighbours in turn, and for every neighbour not already visited mark it as visited and add it to the rear of the queue. Continue until the queue is empty. The effect is to visit all the vertices one edge from the start, then all those two edges away, and so on outwards in layers.

  3. 3

    Describe how a depth-first search works.

    Model answer

    Start at a chosen vertex, mark it as visited and push it onto a stack. Then repeatedly look at the vertex on top of the stack: if it has an unvisited neighbour, mark that neighbour as visited and push it on top; if it has none, pop it and backtrack to the vertex beneath. Continue until the stack is empty. The effect is to follow one path as far as it will go before backtracking to try alternatives. It can equivalently be written recursively, with the call stack doing the same job.

  4. 4

    Which data structure does each of breadth-first and depth-first search use, and why?

    Model answer

    Breadth-first search uses a queue. Because a queue is first in, first out, vertices are dealt with in the order they were discovered, so nearer vertices are always explored before further ones. Depth-first search uses a stack. Because a stack is last in, first out, the most recently discovered vertex is explored next, which drives the search deeper along one path and provides the backtracking when a dead end is reached.

  5. 5

    A graph has vertices A, B, C, D, E, F and undirected edges A-B, A-C, B-D, C-E, D-F and E-F. Give the breadth-first traversal from A, taking neighbours in alphabetical order.

    Model answer

    A, B, C, D, E, F. A is visited and queued. Taking A, its neighbours B and C are visited and queued. Taking B, its unvisited neighbour D is visited and queued. Taking C, its unvisited neighbour E is visited and queued. Taking D, its unvisited neighbour F is visited and queued. Taking E, its neighbours C and F are already visited. Taking F, both its neighbours are visited, and the queue is empty.

  6. 6

    Using the same graph — vertices A to F with edges A-B, A-C, B-D, C-E, D-F and E-F — give the depth-first traversal from A, taking neighbours in alphabetical order.

    Model answer

    A, B, D, F, E, C. From A the first unvisited neighbour is B, from B it is D, from D it is F, from F the unvisited neighbour is E, and from E it is C. C has no unvisited neighbours, so the search backtracks all the way, popping E, F, D, B and A in turn, and finishes.

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.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

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.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

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

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

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

Head means the first single element of a non-empty list.
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.

Fundamentals of Algorithms revision questions

What does Fundamentals of Algorithms cover in AQA A-Level Computer Science?
6 subtopics: graph traversal, tree traversal, reverse polish notation, searching algorithms, sorting algorithms and optimisation algorithms. Each one has its own page with questions and model answers.
How is Fundamentals of Algorithms organised?
By the AQA 7517 specification, subtopic by subtopic, so it matches the order you are taught it in.

Every question in Fundamentals of 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.