How do you implement binary search code in visual basic?

1 Answer

Answer :

The optimal binary search algorithm uses a sorted array as thedata container. Define the range to be searched using a half-closedrange of indices [begin:end). Initially, this will be thehalf-closed range of the whole array.The algorithm is as follows:If begin>=end, this would indicate the range is empty orinvalid, thus the value cannot exist. We return the end iterator toindicate value not found.If the range has one or more elements, then we calculate themiddle index of the range:middle = begin + (end - begin) / 2Note: division takes precedence over addition.We then compare the value in the middle of the range with thevalue being searched. If they are equal, we are done, we simplyreturn the middle index.Otherwise, if the value being searched is less than the middlevalue, we adjust the upper bound of the array so the next iterationonly searches the lower half of the original range:new_end = middleOtherwise we adjust the lower bound of the array so the nextiteration only searches the upper half of the range:new_begin = middle + 1We then repeat the algorithm using the adjusted half-closedrange.The algorithm can be implemented in Visual Basic as follows.Note the array, a, is passed by reference (ByRef) to prevent makingan unnecessary copy of the array. The function does not make anychanges to the array itself so there's no need to copy it.Function bin_search (ByRef a As Integer(), ByVal begin AsInteger, ByVal end As Integer, ByVal value As Integer) AsInteger' save the end iterator (it may change later)Dim not_found As Integer = end' while the range is valid...While begin < end' calculate middle indexDim middle As Integer = begin + (end - begin) / 2' compare the middle element for equalityIf value = A[middle] Then' value found!Return middleEnd If' value not found, so determine which half of array toeliminateIf value < A[middle] Then' eliminate upper half (if value exists, it must be in the lowerhalf)end = middleElse' eliminate lower half (if value exists, it must be in upperhalf)begin = middle + 1End If' repeat algorithm...End While' if we get this far, the range is either empty or invalid(begin>=end), so the value does not existReturn not_foundEnd Function

Related questions

Description : Assume a systems development project effort calculation determines that the system  will require 240 function points. If the developers choose to implement this system in the  C programming language, approximately ... without more information  c. exactly the same  d. much greater  e. much less

Last Answer : e. much less

Description : Write a program to implement the concept of virtual base class for following figure. Accept and display information of one employee with his name, code, basic pay, experience and gross salary with the object of employee class.

Last Answer : #include<iostream.h> #include<conio.h> class Master  {  char name[10],code[3];  public:  void acceptM() { cout<<"\nEnter name and code "; cin>>name>>code; ... .displayM(); e.displayA(); e.displayD(); e.displayE(); getch();  }

Description : In Visual Basic for Applications, is it possible to capture a program initializing and stop it, so it doesn't inturrupt YOUR code?

Last Answer : I’m no expert, but you can try “Doevents” For example: If a=b then Doevents End If

Description : BASIC stands for: a) Basic Access towards Skills in Computer b) Beginner's All Purpose Symbolic Instruction Code c) Binary And Specific Instruction Code d) None of These

Last Answer : b) Beginner's All Purpose Symbolic Instruction Code

Description : Kartoo and other next-generation search engines with visual interfaces - Why do most people stick with traditional result lists?

Last Answer : Google won for being clutter free and fast. Honestly, the results could have been shit and it still would have won. I don’t want a portal or fancy shit. I want search. Google does the best job. Personally, I find the search at Yahoo better, but the interface sucks ass. So I use Google.

Description : What visual technique should be used when searching for an aircraft? a. Sweep from side to side with the eyes covering the whole field of vision b. Search the sky portion by portion starting ... the sky and confirm before passing onto another d. Use a succession of small and rapid eye movements

Last Answer : c. Pinpoint 10° segments of the sky and confirm before passing onto another

Description : What visual technique should be used when searching for an aircraft? a. Sweep from side to side with the eyes covering the whole field of vision b. Search the sky portion by portion starting ... the sky and confirm before passing onto another d. Use a succession of small and rapid eye movements

Last Answer : c. Pinpoint 10° segments of the sky and confirm before passing onto another

Description : What visual technique should be used when searching for an aircraft? a. Sweep from side to side with the eyes covering the whole field of vision b. Search the sky portion by portion starting ... the sky and confirm before passing onto another d. Use a succession of small and rapid eye movements

Last Answer : c. Pinpoint 10° segments of the sky and confirm before passing onto another

Description : How to implement a JavaScript code that doing "Set as my Home Page" in Google Chrome?

Last Answer : So, you’re saying the JavaScript code for doing this works in IE and Firefox, but not Chrome? That’s weird. Let me see if I can find a script for you.

Description : Write some code to implement an indexer.

Last Answer : using System; namespace Console1 { class Class1 { static void Main(string[] args) { MyIndexableClass m = new MyIndexableClass(); Console.WriteLine(m[0]); Console.WriteLine(m[1]); Console.WriteLine(m[2]); Console. ... get { return myData[i]; } set { myData[i] = value; } } } }

Description : Write some code to implement a jagged array. 

Last Answer : // Declare the array of two elements: int[][] myArray = new int[2][]; // Initialize the elements: myArray[0] = new int[5] {1,3,5,7,9}; myArray[1] = new int[4] {2,4,6,8};

Description : Write some code to implement a multidimensional array.

Last Answer : int[,] b = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}}; 

Description : Which of the following statements about the Crime and Criminal Tracking Network System (CCTNS) is/are correct? 1. It will facilitate real time access of classified criminal data to the law enforcement authorities. 2. National Crime ... below- 1) 1 only 2) 2 only 3) Both 1 and 2 4) Neither 1 nor 2

Last Answer : 1) 1 only

Description : What would be the .exe file for a Visual Basic program?

Last Answer : The exe in the bin folder within the (startup) project.

Description : Is this possible to do in Visual Basic?

Last Answer : Well, there's Excel VBA that you can try. There are some tricky ways to change the appearances of scatter charts; or you may try other chart types. If you don't like scatter chart, let me know ... go and tune in to your needs. You may check these out for conditional formatting: one, two, three.

Description : Is there a Visual Basic 6 C++ Alternative?

Last Answer : VB6 will run on Vista with some help. However, your simplest path to working with it out of the box is to either turn off UAC - recommended if you do any kind of software development on Vista (actually, ... get it set up. There is an express version for VB, too. http://www.microsoft.com/express/vc/

Description : Question about the Split Function in Visual Basic?

Last Answer : quit lurking and write something to help her for heaven’s sake! the girl is desperate and the clock is ticking

Description : What is Visual Basic ?

Last Answer : Visual Basic is a third generation event driven programming language.

Description : I know I've asked this once, but it was deleted for some reason. But I should do that if you write two numbers in TextBox1, then add a colon, and if you write two more, one more ... in an existing Visual BAisc programming language can be converted to ec # somehow? thanks in advance for the answers!

Last Answer : answer:

Description : Programming With Visual Basic.NET?

Last Answer : Visual Basic .NET is the latest incarnation of Visual Basic. Itis sometimes known as VB7, a misnomer on account of itsincompatibility with VB6: new features and syntax within VB7 meanthat a re-write, ... a good formdesigner.3. Start up a Visual Basic .NET IDE and make a Windowsapplication.4. D

Description : In Visual Basic .NET or Visual C# programming, when would you use Structured Query Language (SQL)? How are they executed? 

Last Answer : ADO.NET handles most of the database communication for you behind-thescenes. You would only use SQL statements when generating ad-hoc queries for the database. You execute SQL statements by ... returning statements, such as DELETE, INSERT INTO, or UPDATE statements, use the ExecuteNonQuery method.

Description : But won't most .NET developers eventually choose C# over Visual Basic.NET? 

Last Answer : No. Because the power of the two languages is so similar, the primary factor for developers migrating to the .NET world will probably be the syntax they prefer. Since many more developers ... the dominant language for building Windows applications five years from now will still be Visual Basic. 

Description : Power Point 97 incorporated the _______language , underlying all macro generation in office 97: a) Visual Basic for Applications b) Visual Basic for Software c) Virtual Base Language d) None of These

Last Answer : a) Visual Basic for Applications

Description : The window version of Excel supports programming through Microsoft's Visual Basic for Applications (VBA), which is a dialect of _____: a) Visual Support b) Visual Basic c) Visual Format d) None of These

Last Answer : b) Visual Basic

Description : VBA stands for: a) Visual Basic For Application b) Virtual Based For Application c) Various Basics Application d) None of These

Last Answer : a) Visual Basic For Application

Description : 103. Which one is the Low Level Language: a) Assembly b) Visual Basic c) Java d) C++ e) None of The Above

Last Answer : a) Assembly

Description : What second programming language did Google add for App Engine development? A. C++ B. Flash C. JavaD. Visual Basic

Last Answer : Java

Description : What second programming language did Google add for App Engine development? A. C++ B. Flash C. Java D. Visual Basic

Last Answer : Java

Description : How do you do an optimal binary search on a two variable function?

Last Answer : You need to clarify your terminology a little bit. Symmetric about the diagonal? Strictly increasing with respect to which ordering of the pairs?

Description : How do i write a program in c langua ge for the implementation of binary search with output?

Last Answer : send your answer with source code and output for pratical

Description : How do i write a program in c langua ge for the implementation of binary search with output?

Last Answer : send your answer with source code and output for pratical

Description : Which algorithm is used in layered Feed forward Neural Network? (A) Back propagation algorithm (B) Binary Search (C) Both(A) & (B) (D) None of the Above

Last Answer : (A) Back propagation algorithm

Description : Which is true regarding BFS (Breadth First Search)? a) BFS will get trapped exploring a single path b) The entire tree so far been generated must be stored in BFS c) BFS is not guaranteed to find a solution if exists d) BFS is nothing but Binary First Search

Last Answer : b) The entire tree so far been generated must be stored in BFS

Description : To eliminate the inaccuracy problem in planning problem or partial order planning problem we can use ___________________ data structure/s. a) Stacks b) Queue c) BST (Binary Search Tree) d) Planning Graphs

Last Answer : d) Planning Graphs

Description : What is the difference between linear and binary search?

Last Answer : A: Linear search does not require the array to be sorted, whereas, binary search requires that the array be sorted. Linear search checks for the search item in a linear fashion from the beginning cell till the end, ... tell what is control variable in your loop. So if your loop is for(int i = 1; i

Description : When does Binary search fail?

Last Answer : A: When the array is not sorted.

Description : In general, the binary search method needs no more than ……………. comparisons. A) [log2n]-1 B) [logn]+1 C) [log2n] D) [log2n]+1

Last Answer : D) [log2n]+1

Description : State True or False. i) Binary search is used for searching in a sorted array. ii) The time complexity of binary search is O(logn). A) True, False B) False, True C) False, False D) True, True

Last Answer : D) True, True

Description : In ……………, search start at the beginning of the list and check every element in the list. A) Linear search B) Binary search C) Hash Search D) Binary Tree search

Last Answer : A) Linear search

Description : A binary search tree whose left subtree and right subtree differ in hight by at most 1 unit is called A) AVL tree B) Red-black tree C) Lemma tree D) None of the above

Last Answer : A) AVL tree

Description : Consider the following statements: (a) Depth - first search is used to traverse a rooted tree. (b) Pre - order, Post-order and Inorder are used to list the vertices of an ordered rooted tree. (c) Huffman's algorithm is used to find an optimal ... (d) (C) (a) , (b) and (c) (D) (a), (b) , (c) and (d)

Last Answer : (D) (a), (b) , (c) and (d)

Description : Suppose that we have numbers between 1 and 1000 in a binary search tree and want to search for the number 364. Which of the following sequences could not be the sequence of nodes examined? (A) 925, 221, 912, 245, 899, ... 926, 203, 912, 241, 913, 246, 364 (D) 3, 253, 402, 399, 331, 345, 398, 364 

Last Answer : (C) 926, 203, 912, 241, 913, 246, 364

Description : Consider the following binary search tree: If we remove the root node, which of the node from the left subtree will be the new root? (A) 11 (B) 12 (C) 13 (D) 16

Last Answer : (D) 16

Description : The runtime for traversing all the nodes of a binary search tree with n nodes and printing them in an order is (A) O(lg n) (B) O(n lg n) (C) O(n) (D) O(n2 ) 

Last Answer : (C) O(n) 

Description : Which of the following statements is false? (A) Optimal binary search tree construction can be performed efficiently using dynamic programming. (B) Breadth-first search cannot be used to find connected components of a graph. (C) ... used to find the components of a graph. (1) A (2) B (3) C (4) D 

Last Answer : Answer: 2

Description : The language made up of binary coded instructions. a) Machine b) C c) BASIC d) High level

Last Answer : Answer: a Explanation: The language made up of binary coded instructions built into the hardware of a particular computer and used directly by the computer is machine language

Description : The only language which the computer understands is ______________ a) Assembly Language b) Binary Language c) BASIC d) C Language

Last Answer : Answer: b Explanation: The Computer understands only binary language which is written in the form of 0s & 1s. A computer can understand assembly language but an assembler is ... language to binary language. Similarly, for understanding high level languages, compilers/interpreters are required

Description : BCD- How many binary code ?

Last Answer : BCD quote consists of 6 bits.

Description : What is Tina in binary code?

Last Answer : That would depend on which computer character code you want to use, there have been thousands of them. The most current is Unicode an extension of ASCII. Unicode can support every living language on earth ... the following Hexadecimal bytes (you can convert to binary):T = E3Hi = 89Hn = 95Ha = 81H

Description : Who Came up with the binary code?

Last Answer : Feel Free to Answer