Extract sample (w/o replacement) - Page 2

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: Extract sample (w/o replacement)

Quoted text here. Click to load it

Not quite. The cost is proportional to the size of the part of the array
which has to be moved. Removing a single element at the start or end of
the array is very cheap, removing one from the middle of a large array
rather costly.  

Also, the cost is not symmetrical: Removing an element from the second
half is cheaper than removing one from the first half: On my desktop,
using perl 5.14, removing a single element from just before the middle
of a 100000 element array takes a bit over 50 µs, removing one just
after the middle a bit under 20 µs. Both halves are linear, so an
obvious (but probably very minor) optimization would be to change the
method after the first third instead of after half.

Quoted text here. Click to load it

This is sometimes worthwhile but, as Rainer already pointed out, not in
this case.


   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel

Site Timeline