From: "Matthew, Graeme" Date: 2002-11-01T13:22:35+09:00 Subject: Re: Binary search ok, I am actually using a binary search in a vb (yes sorry, I wish I could convice my manager to use ruby, but he does not have a clue !!!) ok firstly the column (array element you are going to search on) needs to be unique and sorted ascending find the mid point (pivot) by taken the number of items in the array and divide by 2 (or the closest) if the value you want to find is equal to the mid point value then get it and exit if less than then find the half way point between the mid point and start if greater than then find the halfway point between midpoint and end now you keep doing this until you find the value, its a divide and conquer routine Does this help ??? Graeme Matthew Analyst Programmer Mercer Investment Consulting Level 29, 101 Collins Street, Melbourne, VIC, 3001, Australia Tel - 61 3 9245 5352 Fax - 61 3 9245 5330 visit http://www.merceric.com -----Original Message----- From: Gavin Sinclair [mailto:gsinclair@soyabean.com.au] Sent: Friday, 1 November 2002 15:03 To: ruby-talk@ruby-lang.org Subject: Re: Binary search From: "martin tran" > Hi, I am having problem converting the following algorithm (shown below) > into ruby code. > > :find j such that B[j] <= A[length/2] B[j+1] using binary search > > Can anyone help me please, > > Thanks, > Tim I ususally turn out to be wrong in these matters, but my answer is: "only if you explain the algorithm better". Gavin __ ********************************************** This e-mail and any attachments may be confidential or legally privileged. If you received this message in error or are not the intended recipient, you should destroy the e-mail message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained herein. Please inform us of the erroneous delivery by return e-mail. Thank you for your cooperation. ********************************************** ec03/04