Initializing an array of n elements using the O (1) function?

anyone has an idea how can i do this?

thank

+3
source share
8 answers

It smells like a domestic problem, but I'll throw you a bone ...

http://eli.thegreenplace.net/2008/08/23/initializing-an-array-in-constant-time/

+11
source

If you need to do something for each element in a set of elements n, you cannot do it better than O ( n) performance .

+5
source

" N , N", . , , .

, . ( hashmap, , ), .

+4

, . ++ :

int foo[1000] = {0};

0

, O (n)

+1

, , . , n, O(n); , , , .

; , O(n), O(n), O(1).

. reset, , , . , , .

+1

O (1), Amortized Analysis . ( ).

+1

O (1). .

0

. . , O (n * 1/k), k - . O (n), .

-1

All Articles