kaveman50 Posted December 5, 2009 Share Posted December 5, 2009 Does anyone know how to do (or at least help me get started on) a binary search? I have to create a list of 25 names in alphebetical order. Create a binary search program that searches for an input name. Tell the user whether or not the name was found. The names i'll use will be. $arr=array('Allen', 'Brad', 'Chris', 'Drake', 'Eugene',' Frank', 'Greg', 'Hank', 'Ingrid', 'Jim', 'Kraig', 'Lee', 'Molly', 'Nathan', 'Otis', 'Peter', 'Quame', 'Rolland', 'Sean', 'Tiffany', 'Utopia', 'Venus', 'Walley', 'Xephinorgi', 'Yullanda', 'Zeus'); Quote Link to comment https://forums.phpfreaks.com/topic/184095-binary-search/ Share on other sites More sharing options...
rajivgonsalves Posted December 5, 2009 Share Posted December 5, 2009 binary search why not use in_array http://php.net/manual/en/function.in-array.php Quote Link to comment https://forums.phpfreaks.com/topic/184095-binary-search/#findComment-971924 Share on other sites More sharing options...
Drippingblood123 Posted December 5, 2009 Share Posted December 5, 2009 because I'm just a beginner and I need to know how to do a binary search Quote Link to comment https://forums.phpfreaks.com/topic/184095-binary-search/#findComment-971939 Share on other sites More sharing options...
rajivgonsalves Posted December 5, 2009 Share Posted December 5, 2009 how about array_search that seems to be much better in this situation Quote Link to comment https://forums.phpfreaks.com/topic/184095-binary-search/#findComment-971946 Share on other sites More sharing options...
salathe Posted December 5, 2009 Share Posted December 5, 2009 Is this some homework assignment, to demonstrate an understanding of the algorithm? [ot]Why do the two posts from whom I assume to be the OP from different usernames?[/ot] Quote Link to comment https://forums.phpfreaks.com/topic/184095-binary-search/#findComment-971949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.