2.3.1. Analysis, Design and Comparison of Algorithms
2.3.1. Analysis, Design and Comparison of Algorithms
https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc
Analysis of Algorithms
● There are two things you check when developing an algorithm:
○ Time Complexity
○ Space Complexity
Time of Complexity
● How much time an algorithm requires to solve a particular problem
● The time complexity is measured using a notation called big-o notation, it shows the
effectiveness of the algorithm
● It shows the amount of time taken relative to the number of data elements given as
an input
● This is good because it allows you to predict the amount of time it takes for an
algorithm to finish given the number of data elements
https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc
Logarithms
● A logarithm is similar to the inverse of an exponential
● the logarithms is an operation that determines how many times a certain number
(base) is multiplied by itself to reach another number
● It might help to check the extra resources for more information on this
x y = log(x)
1 (20) 0
8 (23) 3
1024 (210) 10
Space Complexity
● The space complexity of an algorithm is the amount of storage the algorithm takes
● Space complexity is commonly expressed using Big O (O(n)) notation.
● Algorithms store extra data whenever they make a copy, this isn’t ideal
● When working with lots of data, it’s not a good idea to make copies. As this will take
lots of storage which is expensive.
Designing Algorithms
https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc
Comparison of Algorithms
Linear Search Algorithm
● An algorithm which traverses through every item one at a time until it finds the item
its searching for
● The Big-O notation for a linear search algorithm is O(n)
https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc