in reply to Insert Into a Sorted Array
The mergesort version of sort in perl 5.8+ will do that as well as anything1 by just sorting in the new value,
The quicksort of previous versions of perl is bad for this. It has a quadratic worst case for nearly sorted lists. 1 Actually not as good as a binary search for a single insertion point, which is O(logN). That is how you'd perform your own suggestion. As tachyon says, though, insertion with splice is still O(N/2).@known = sort byIndex @known; @known = sort byIndex $newValue, @known;
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Insert Into a Sorted Array
by ketema (Scribe) on Sep 29, 2004 at 03:30 UTC | |
by Zaxo (Archbishop) on Sep 29, 2004 at 03:44 UTC |