• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting Time Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting Time Question


  • Subject: Re: Sorting Time Question
  • From: Matt Ronge <email@hidden>
  • Date: Wed, 26 Mar 2003 22:30:50 -0600

> 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.

This really depends on the size of your data set and how often items will be
added and removed.

For a small data set it would be best to replace the old value and use the
built in sort. Or you could use an insertion sort. Insertion sorts are good
for data that is partially sorted. Or there might be an even better sort
depending on what type of data is being stored (radix sort, math sort, etc.)

For a larger data set I would remove the item and do a binary search and
insert the data. However, depending on where you are holding the data an
insertion could be very expensive.

If insertions are very expensive or occur frequently or insertions occur in
one large group I would use a binary tree. A binary tree would make adding
and removing the fastest and if you need a complete sorted listed you can
always do an inorder traversal of the binary tree.

Anyway, I hope that helps.
--
Matt Ronge

"If the professors of English will complain to me that the students who come
to the universities, after all those years of study, still cannot spell
'friend,' I say to them that something's the matter with the way you spell
friend." - Richard P. Feynman, April 1963
_______________________________________________
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.

References: 
 >Sorting Time Question (From: Francisco Tolmasky <email@hidden>)

  • Prev by Date: Re: [OT] Macho Love
  • Next by Date: Component Manager Message...
  • Previous by thread: Re: Sorting Time Question
  • Next by thread: Executing short AppleScript command sets
  • Index(es):
    • Date
    • Thread