Charora's website  
Home arrow Technical Articles arrow Scripting! - VBScript, Javascript, WSH arrow Binary Search Algorithm using VBScript
Thursday, 09 September 2010
 
 
Binary Search Algorithm using VBScript PDF Print E-mail
Written by Sushma Charora   
Wednesday, 30 August 2006
Binary Search Algorithm implemented in VBScript. Copy this script and use it for a multi-dimensional array.

Function BinarySearch(searchItem, startPos, endPos, TheArray, column_to_be_searched)
Dim midPoint
If startPos = endPos Then
If searchItem = TheArray(startPos, column_to_be_searched) Then
BinarySearch = startPos
Else
BinarySearch = -1 '-(startPos) Where it would have been...
End If
ElseIf startPos > endPos Then
BinarySearch = -1 '-(startPos)
Else
midPoint = CLng(startPos + ((endPos - startPos) / 2))
If searchItem = TheArray(midPoint, column_to_be_searched) Then
BinarySearch = midPoint
Else
If searchItem < TheArray(midPoint, column_to_be_searched) Then
BinarySearch = BinarySearch(searchItem, startPos, midPoint - 1, TheArray, column_to_be_searched)
Else
BinarySearch = BinarySearch(searchItem, midPoint + 1, endPos, TheArray, column_to_be_searched)
End If
End If
End If
End Function 'BinarySearch

Comments

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Personal verbal attacks will be deleted.
  • Please don't use comments to plug your web site. Such material will be removed.
  • Just ensure to *Refresh* your browser for a new security code to be displayed prior to clicking on the 'Send' button.
  • Keep in mind that the above process only applies if you simply entered the wrong security code.
Name:
E-mail
Homepage
Title:
BBCode:Web AddressE-mailBold TextItalic TextUnderlined TextQuoteCodeOpen ListList ItemClose List
Comment:



Code:* Code:

Last Updated ( Tuesday, 06 November 2007 )
 
< Prev   Next >
Google





Lost Password?
No account yet? Register
Archive
Newsflash
Vision is the art of seeing things invisible.
-- Jonathan Swift

To achieve great things, we must live as though we were never going to die.
-- Vauvenarges

The moment you stop learning, you stop leading.
-- Rick Warren

Most people would rather die than think, many do.
-- Eleanor Roosevelt

To a man with empty stomach, food is God.
-- M. K. Gandhi

We are only rich through what we give.
-- Anne-Sophie Swetchine

If you haven't any charity in your heart, you have the worst kind of heart trouble.
-- Bob Home

In a war of ideas, it is people who get killed.
-- Anonymous

The cobra will bite you whether you call it cobra or Mr. Cobra.
-- an Indian Proverb

If we had no winter, the spring would not be so pleasant.
-- Anne Bradstreet

It takes a lot of things to prove that you are smart, but only one to prove you are not.
-- Don Harold

Whenever you have truth, it must be given with love, or the message and the messenger both will be rejected.
-- Mahatma Gandhi

Forgiveness is a scent that the rose leaves on the heel that crushes it.
-- Mark Twain

When people think you amount to something, distrust yourself.
-- Epicectus, Stoic Philosophy

Fear not death; for the sooner we die, the longer shall we be immortal.
-- Benjamin Franklin

The world is round and the place which may seem like the end may also be only the beginning.
-- Anonymous

The minute a man is convinced he is interesting, he isn't.
-- Stephen Leacock

 
Related Items
Sections
 
Top! Top!