>> Just compare the middle element, if it is bigger, use the left half, else use the right half.
I don't follow - can you post an Actionscript example? Jason Merrill Bank of America Global Learning Learning & Performance Solutions Join the Bank of America Flash Platform Community and visit our Instructional Technology Design Blog (note: these are for Bank of America employees only) -----Original Message----- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Henrik Andersson Sent: Thursday, May 06, 2010 10:45 AM To: Flash Coders List Subject: Re: [Flashcoders] Doing a binary search in AS3? Merrill, Jason wrote: > I understand what a binary search algorithm is, but am wondering how > that could be implemented on an array in Actionscript (if at all) > without using methods that would defeating the purpose of a binary > search (speed). Anyone have experience in this area? > > So for example, if you have a list like this: > > ["apple", "orange", "banana", "pear", "cherry", "pineapple", "kiwi", > "peach"] > > Then to do a binary search for say, "pineapple", as I understand > binary searching, you would first split the list in the middle (between "pear" > and "cherry") and determine if "pineapple" was in that list - if not, > search the other half and so on until you find "pineapple". That is wrong, you know that it will be in a certain half due to the list being sorted. There is no need to scan the half for the object, by the list already being sorted, you know that if the object exists, it's in that half. Just compare the middle element, if it is bigger, use the left half, else use the right half. _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders