Binary Search: created with Flex Builder 2

Binary Search Flex App Screen CaptureIf you remember back about a year ago now you may recall seeing an algorithm posted on the ActionScript Cheatsheet blog demonstrating how to reverse an Array. There was a distance learning course on UWTV on the C programming langauge and an unrelated blog post that prompted my interest in the reverse algorithm. Recently I was asked about an algorithm to “guess” an integer within a given range. Something about that old reverse algorithm instantly met my mind. The whole left, right, mid concept in particular.

As always curiosity got the best of me and after consulting the usual suspects (google, wikipedia) this little binary search example was born. She was originally created in Flash 9, then she was ported into Flex Builder 2. Click here, or on the image to view the working example. The source can be downloaded here.

I ended up having to put a little hack in place to “auto-scroll” the TextArea’s scroll bar to the bottom. I tried the updateNow and callLater methods but could not get them to work.

If you’re asking “why”, these are types of questions asked to programmers to prove their level of knowledge… So study-study, you never know when someone will ask you one of these questions. For CS Majors this is probably nothing special but for those of us coming from an arts/media type of background Binary Search may have not been in the curriculum.

2 Responses to “Binary Search: created with Flex Builder 2”

  1. Bug: array.length is one more than maximum array index, since indices are zero-based. If element isn’t found, code walks off the end and element == null

  2. Can you post the source code for this? The current link to the code returns a 404.

Leave a Reply