Complexity Analysis: how to identify the "basic operation"? -


i taking class on complexity analysis , try determin basic operations of algorithms. defined following:

a basic operation 1 best characterises efficiency of particular algorithm of interest

for time analysis operation expect have influence on algorithm’s total running time:
- key comparisons in searching algorithm
- numeric multiplications in matrix multiplication algorithm
- visits nodes (or arcs) in graph traversal algorithm

for space analysis operation increases memory usage
- procedure call adds new frame run-time stack
- creation of new object or data structure in run-time heap

the basic operation may occur in more 1 place in algorithm

so i'm trying figure out basic operation of reversearray algorithm.

reversearray(a[0..n-1]) i=0 [n/2]-1    temp <- a[i]    a[i] <- a[n-1-i]    a[n-1-i] <- temp 

my tutor mentioned basic operation "kind of operation" assignment, addition, division , either choose between assignment or subtraction in case of algorithm.

now have exercise asking basic operation of given algorithm. correct basic operation "assignment" , list 3 lines of code inside loop?

in opinion subtraction too, because there 4 of it.

i'm not sure if basic operation commonly recognized term or if expression lecturer chose.

you can take operation (assignment, reading array access, subtraction) basic operation. lead same result:

  1. assignment: 3 * n/2 -> o(n)
  2. reading access: 2 * n/2 -> o(n)
  3. complete for-block: n/2 -> o(n)

it made no difference in example. here stupid example ( no optimized code ), makes difference:

for = 1 n     x = a[i]     j = 1 n         b[j] += x 

obviously, reading access array takes o(n) steps, number of writing operations or additions o(n^2).

the basic operation operation on basis of have calculated complexity. can every operation in code, can lead different results, have shown in example.

for reason, 1 sees phrases like:
the code needs o(n) multiplications , o(n^2) additions.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -