You are on page 1of 3

Algorithm Complexity

An algorithm complexity refers to the amount of resources including time and storage, necessary to execute it. The efficiency or running time is measured by the input length to the number of steps (time complexity), or storage locations (space complexity). For the algorithms below, time complexity is used as the measure of the complexity. Time complexity is expressed using Big O Notation, as seen from here on how to use it and how it is used:

Huffman Algorithm
Algorithm: Huffman(A){ n = |A|; Q = A; for i = 1 to n – 1{ z = new node; left[z] = Extract-Min(Q); right[z] = Extract-Min(Q); f[z] = f[left[z]] + f[right[z]]; Insert(Q,z); } return Extract-Min(Q); } According to (BELL, Rob, 2011), the iterative halving of data sets in a binary heap produces a growth curve that peaks at the beginning and slowly flattens out as the size of the data sets increases is described as a O(log n) algorithm. This describes the loop and the statements in it, since it is using a heap data-structure with work of O(log n). The creation of the 2nd list, Q from A by combining weights from A in a tree shows that it is a binary heap. But the loop is also executed n-1 number of times, with a work of O(n), therefore the final complexity of the algorithm is O(n log n). Complexity: O (n log n)

Rob. This means that the complexity of the above algorithm is O(N2). 2011). the ‘for all’ and ‘while’ loops respectively.Dijkstra’s Algorithm Algorithm: DijkstraAlgorithm (weighted graph. vertex first) for all vertices v currDist(v) =  currDist(first) = 0 toBeChecked = all vertices While toBeChecked is not empty { v = a vertex in toBeChecked with minimal currDist(v) remove v from toBeChecked for all vertices u adjacent to v and in toBeChecked if currDist(u) > currDist(v) + weight(edge(vu)) { currDist(u) = currDist(v) + weight(edge(vu)) predecessor(u) = v } } According to (BELL. The above algorithm is a nested iterative algorithm. O(N4) and so on. or O(|N|2) with respect to absolute value. and deeper nested iterations will result in O(N3). an algorithm whose performance is directly proportional to the square of the size of the input data set is known as an O(N2). This is common with algorithms that involve nested operations. Complexity: O(|N|2) . as shown in line 1 and line 5.

Rob. Available from World Wide Web: <http://rob-bell. 2011.Bibliography BELL. [online].net/2009/06/a-beginners-guide-to-big-o-notation/> . [Accessed 28 September 2011]. A Beginners’ Guide to Big O Notation.