algorithm - Very simple recursive function complexity analysis -
i need understand analysing recursive algorithms. made algorithm up, , know complexity is:
int functionexampple( a1, a2, ... ) { product = 1; if( n == 2) { product = multi(a1, a2); } else { product = multi(a1, functionexample( a2, a3, ..., ) ); } return product; } now assuming function multi takes o(n^1.59) time, complexity be? remain o(n^1.59) or recursive calls make o(n^1.59 * n ) account number of recursive calls? guys.
ps: wrote quickly, , syntax , stuff doesn't matter.
the parameter 'n' in o(n1.59) measures size(s) of arguments 'multi', not number of arguments. crucial how size of output 'multi' relates sizes of inputs. e.g. if result 'multi' twice size of of arguments, call multi(a, multi(b, c)) a, b, c of size n o(n1.59 + (2n)1.59), , if chain multiple calls multi in fashion exponential growth. on other hand, if 'multi' returns values of same size inputs, o(k n1.59) k number of arguments functionexample , n (largest) size.
so depends on how 'multi' behaves. e.g. there huge difference if multiplication versus multiplication within finite field, latter result wouldn't grow inputs, whereas unlimited integers result grows in size.
Comments
Post a Comment