Algorithm Efficiency (AQA GCSE Computer Science)

Revision Note

James Woodhouse

Written by: James Woodhouse

Reviewed by: Lucy Kirkham

Algorithm Efficiency

What is algorithm efficiency?

  • Algorithm efficiency is how much time it takes to complete an algorithm

  • In programming, there is often more than one algorithm which can solve a problem

  • An example of this is a linear search and binary search as both find a value in a list, however, depending on the circumstances, one may be much faster than the other

Efficiency in action

  • If we took the numbers 1-20 jumbled up in a list

  • How efficient an algorithm is would be determined by how quickly it could sort the numbers into ascending order

Sort 1 (Bubble sort)

Sort 2 (Insertion sort)

DEFINE listToSort AS a list of integers containing the numbers 1 to 20

SET lengthOfList TO the length of listToSort

FOR currentIndex FROM 0 TO lengthOfList - 1 DO

    FOR innerIndex FROM 0 TO lengthOfList - 1 - currentIndex DO

        IF listToSort[innerIndex] > listToSort[innerIndex + 1] THEN

            TEMP ← listToSort[innerIndex]

            listToSort[innerIndex] ← listToSort[innerIndex + 1]

            listToSort[innerIndex + 1] ← TEMP

        END IF

    END FOR

END FOR

DEFINE listToSort AS a list of integers containing the numbers 1 to 20

SET lengthOfList TO the length of listToSort

FOR currentIndex FROM 1 TO lengthOfList - 1 DO

    SET currentValue TO listToSort[currentIndex]

    SET innerIndex TO currentIndex - 1

    WHILE innerIndex >= 0 AND listToSort[innerIndex] > currentValue DO

        listToSort[innerIndex + 1] ← listToSort[innerIndex]

        SET innerIndex TO innerIndex - 1

    END WHILE

    listToSort[innerIndex + 1] ← currentValue

END FOR

  • In the algorithms above, the worst case of a bubble sort is that it would take 361 comparisons to sort 20 items of data

  • The worst case of an insertion sort with 20 items is that it would perform 190 comparisons

  • This means that in this instance, although both algorithms perform the same job and achieve the same result, an insertion sort would be significantly faster because it is much more efficient in how it uses the computer’s processing power and memory

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.

Lucy Kirkham

Author: Lucy Kirkham

Expertise: Head of STEM

Lucy has been a passionate Maths teacher for over 12 years, teaching maths across the UK and abroad helping to engage, interest and develop confidence in the subject at all levels.Working as a Head of Department and then Director of Maths, Lucy has advised schools and academy trusts in both Scotland and the East Midlands, where her role was to support and coach teachers to improve Maths teaching for all.