0% found this document useful (0 votes)
7 views

1.2 Algorithm Efficiency

Algorithm efficiency refers to the time it takes to complete an algorithm, with different algorithms available for solving the same problem. For example, a bubble sort requires 361 comparisons while an insertion sort only requires 190 comparisons to sort 20 items, making the latter more efficient. Understanding these differences is crucial for optimizing performance in programming.

Uploaded by

annie.ali.blog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

1.2 Algorithm Efficiency

Algorithm efficiency refers to the time it takes to complete an algorithm, with different algorithms available for solving the same problem. For example, a bubble sort requires 361 comparisons while an insertion sort only requires 190 comparisons to sort 20 items, making the latter more efficient. Understanding these differences is crucial for optimizing performance in programming.

Uploaded by

annie.ali.blog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Head to www.savemyexams.

com for more awesome resources

AQA GCSE Computer Science Your notes

Efficiency of Algorithms
Contents
Algorithm Efficiency

Page 1 of 3
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Algorithm Efficiency
Your notes
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 DEFINE listToSort AS a list of integers containing the
numbers 1 to 20 numbers 1 to 20

SET lengthOfList TO the length of listToSort SET lengthOfList TO the length of listToSort

FOR currentIndex FROM 0 TO lengthOfList - 1 DO FOR currentIndex FROM 1 TO lengthOfList - 1 DO

FOR innerIndex FROM 0 TO lengthOfList - 1 - SET currentValue TO listToSort[currentIndex]


currentIndex DO
SET innerIndex TO currentIndex - 1
IF listToSort[innerIndex] > listToSort[innerIndex + 1]
WHILE innerIndex >= 0 AND listToSort[innerIndex] >
THEN
currentValue DO
TEMP ← listToSort[innerIndex]
listToSort[innerIndex + 1] ← listToSort[innerIndex]
listToSort[innerIndex] ← listToSort[innerIndex + 1]
SET innerIndex TO innerIndex - 1
listToSort[innerIndex + 1] ← TEMP
END WHILE
END IF
listToSort[innerIndex + 1] ← currentValue
END FOR
END FOR
END FOR

Page 2 of 3
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

In the algorithms above, the worst case of a bubble sort is that it would take 361 comparisons to sort
20 items of data
Your notes
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

Page 3 of 3
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers

You might also like