Pseudocode for Binary Search Method in Sorting List (for VB2008)

Declare search_value As String
Declare n As Integer

Input n
Declare list(1 to n) As String
Input search_value

Declare i As Integer
For i=0 to n-1 Increased by 1
     Input list(i)
End For

Declare start_index As Integer
Declare end_index As Integer
Declare mid_index As Integer
Declare found_index As Integer
Set start_index=1
Set end_index=n

Set found_index = -1

Do
     mid_index = (Round Down) (start_index+end_index)/2
     If end_index<=start_index Then
          If search_value = list(mid_index) Then
               found_index = mid_index
          End If
          
Exit Do
      Else
          If search_value = list(mid_index) Then
               found_index = mid_index
               Exit Do
           Else If search_value < list(mid_index) Then
                end_index = mid_index – 1
           Else
                start_index = mid_index + 1
           End If
     End If
End Do Loop

If found_index = -1 Then
     Display “Search not found!”
End If

Output found_index

(Reference: http://www.krookroo.com/programming-languages/ms-visual-basic-20052008/94-it-vb9-10.html)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: