Re: Sorting Time Question
Re: Sorting Time Question
- Subject: Re: Sorting Time Question
- From: ryan <email@hidden>
- Date: Wed, 26 Mar 2003 19:45:01 -0800
On 3/26/03 7:30 PM, "Francisco Tolmasky" <email@hidden> wrote:
>
Ok, if I have a self sorting array, when an object changes it must be
>
resorted. Should I just call sortUsingFunction: or whatever, or is it
>
worth it to implement a function that removes this item and reinserts
>
it itself, possibly using a binary search to find where it belongs.
Best sorting algorithm: O( n log n )
Best binary search algorithm: O( log n )
From that, its obvious that using the re-insertion is the faster solution.
If your list is really small, and will stay small, its probably easier to
just call sortUsingFunction:.
Hope this helps.
-ryan
>
>
So basicall, if this is the original:
>
>
1
>
2
>
3
>
>
and 2 is changed to 5, then should I resort, OR do this
>
>
remove 2, leaving:
>
>
1
>
3
>
>
insert 5:
>
>
1
>
3
>
5
>
>
>
Francisco Tolmasky
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.