Difference between revisions of "Comparing Algorithms - Big O"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Logarithmic complexity - O(log n))
(Logarithmic complexity - O(log n))
Line 11: Line 11:
  
 
===== Logarithmic complexity - O(log n)=====
 
===== Logarithmic complexity - O(log n)=====
An algorithm with logarithmic complexity is better than a linear complexity for searching, because it will grow in time in comparison with items, but not as fast.
+
An algorithm with logarithmic complexity is better than a linear complexity for searching, because it will grow in time in comparison with items, but not as fast. For example when you search a list, and see that it's not in the middle, it will cut the list in half and then it searches in that half, so the time is reduced as the list gets split.
  
 
===== Linearithmic complexity - O(nlog n)=====
 
===== Linearithmic complexity - O(nlog n)=====

Revision as of 08:42, 16 May 2017

Big O Notation is a measure of how long or how much memory is needed to execute and algorithm. This uses the worst case scenario, so that you get the maximum time and memory usage. It uses n as the number of items.

Time complexities:

Constant complexity - O(1)

An algorithm with constant complexity means that the time taken doesn't increase regardless of the items that you process. So you could have 10000 items and it would take 1 second, and 100 items and it would still take 1 second.

Linear complexity - O(n)

An algorithm with linear complexity takes more time as you give it more items to process. So the larger the n value is, the longer it takes. For example planting seeds in a small field would take longer than planting the same amount of seeds but spread out in a larger field.

Logarithmic complexity - O(log n)

An algorithm with logarithmic complexity is better than a linear complexity for searching, because it will grow in time in comparison with items, but not as fast. For example when you search a list, and see that it's not in the middle, it will cut the list in half and then it searches in that half, so the time is reduced as the list gets split.

Linearithmic complexity - O(nlog n)
Polynomial complexity - O(nk)
Exponential complexity - O(kn)
Factorial complexity - O(n!)