Friday, 15 March 2013

java - determine complexity class -



java - determine complexity class -

what big o notation here? explanation appreciated. thanks.

public static int[] mystery1(int[] list) { int[] result = new int[2 * list.length]; (int = 0; < list.length; i++) { result[2 * i] = list[i] / 2 + list[i] % 2; result[2 * + 1] = list[i] / 2; } homecoming result; }

it o(n), n length of list. go through entire list 1 time in case.

the number of arithmetic operations are:

2n multiplications 2n additions 2n divitions n modulo operations

this not counting arithmetic operations implementing loop.

java performance complexity-theory big-o

No comments:

Post a Comment