Efficiency of algorithms

<< Previous: Sorting algorithms Next: Algorithms test >>

Often more than one way to do it

When it comes to designing algorithms, there is often more than one way to solve a problem. This gives rise to the need to compare the efficiency of different algorithms that could be used to solve a problem.

Time efficiency

Although there are other measures of efficiency, the one you will be asked to comment on in exams will be time efficiency. This refers to the amount of time it takes for the algorithm to execute. it is important to realise that sometimes an algorithm which contains more lines of code may execute more efficiently.

The linear search algorithm used on an unsorted list has a time efficiency of O(n), where n is the number of items in the list. The binary search algorithm has a value of O(log n), where n is the number of items in the list. Notice the gap at the start of the graph. A binary search does not make sense with a very short list.

As another divide and conquer algorithm the merge sort also has a time compexity of O(log n). The bubble sort makes a large number of checks. It is essentially a nested loop where each loop may run as many as n times. This means it has a time complexity of O(n2)

Knowledge check


Questions:
Correct:

Question text


<< Previous: Sorting algorithms Next: Algorithms test >>

© All materials created by and copyright S.Goff