GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-Mar-2007, 04:44
CaCao CaCao is offline
New Member
 
Join Date: Mar 2007
Posts: 11
CaCao is on a distinguished road

Binary search algorithm


Hey guys I need a big help.

I have an algorithm about binary search and I need this algorithm's program.
couldnt do it

If anyone can do it for me I will be so happy.

here is the algorithm:
__________________________________________________ ____________
1.0 Let the bottom be the initial array elements.

2.0 Let the top be the last array elements.

3.0 Let found false.

4.0 Repeat as long as bottom is not greater than top and target has not been found.

4.1 Let the middle be subscript of the element half way between bottom
and top.

4.2 If the element middle is target

4.2.1 Set found to true and index ot middle.

4.3 Let top be the middle-1

__________________________________________________ _________
  #2  
Old 31-Mar-2007, 05:45
mathematician mathematician is offline
Member
 
Join Date: Nov 2006
Location: Shrewsbury Uk
Posts: 131
mathematician will become famous soon enough

Re: Help me plss :(


If you have reproduced it correctly, somebody has given you a flaky algorithm. That's not how you do a binary chop.
  #3  
Old 31-Mar-2007, 15:08
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,893
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Help me plss :(


Quote:
Originally Posted by mathematician
If you have reproduced it correctly, somebody has given you a flaky algorithm. That's not how you do a binary chop.

Indeed.

Problem statement for an array of integers:

Code:
Given a array of ints, array[], sorted in ascending order, and int variables "target", "bottom" and "top". "bottom" and "top" are the values of the indices of the first and last elements of the array to be searched. We are looking for the index of an element whose value is equal to "target".

Binary search algorithm to be implemented in C:

Code:
Declare an integer variable "probe". Declare an integer variable "found". Set found = 0. While (bottom is not greater than top) and (found is equal to 0) Begin Loop Set probe = (bottom + top) / 2. If array[probe] is equal to the target value then Set found = 1. Else If array[probe] is greater than the target then Set top = probe-1. Else Set bottom = probe+1. End If End Loop Upon leaving the loop, if "found" == 1, then "probe" is the index of an array element that is equal to the target value.


Regards,

Dave
  #4  
Old 01-Apr-2007, 04:42
CaCao CaCao is offline
New Member
 
Join Date: Mar 2007
Posts: 11
CaCao is on a distinguished road

Re: Help me plss :(


Quote:
If you have reproduced it correctly, somebody has given you a flaky algorithm. That's not how you do a binary chop.

The only information i have is that. Thats why I couldnt do anything.

Thanks a lot Dave
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:47.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.