What is the difficulty -[NSArray insertObject:atIndex:]- N? or a constant?
-[NSArray insertObject:atIndex:]
N
Also, how can I find out the complexity of various Objective-C statements?
The discussion and source code for CFArray.h are discussed here:
Computational complexityThe access time for a value in an array is guaranteed to be in the worst case O (log N) for any implementation, current and future, but often there will be O (1) (constant time). Linear search operations likewise have worse O (Nlg N) complexity, although usually the boundaries will be stricter and so on. Insertion or deletion operations will usually be linear in the number of values in the array, but may be O (Nlg N) explicitly in the worst case in some Implementations. There are no favorable positions in the array for presentation; that is, it is not necessary to access values with low indices faster or to insert or delete values with high indices or whatever.
, Foundation .
, , Foundation, , , NSMutableDictionary.
(afaik), , , :
http://ridiculousfish.com/blog/archives/2005/12/23/array/index.html
Just a nit choice: NSArrayor CFArraynot part of the language, its Core Foundation class. You can take a look at the source code of CFArray to justify its complexity, but it looks like it will take some time :) If you are concerned about the real work (unlike the theoretical point of view), do the test and profile.
NSArray
CFArray
This is not stated in the official docs, but I think it looks like lists of arrays in other languages that would be O (n).