LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary search

Does anybody have any information on how to do a binary search? I am looking for a specific output value and do not want to go through all the possible input values to find that output value.
0 Kudos
Message 1 of 5
(6,155 Views)
One possible solution is to convert the binary values into a 1D array of numerics and then use the 'Search 1D Array' LabVIEW primitive to find the value of interest.

Chris_Mitchell
Product Development Engineer
Certified LabVIEW Architect

0 Kudos
Message 2 of 5
(6,155 Views)
Binary search method. Do you mean a divide by two method? For a given range move the sample to the middle of the range, test for a pass/fail. the pass/fail answer determinds the direction and the remainder of the range is the divided by 2 again?
0 Kudos
Message 3 of 5
(6,155 Views)
You need to start with an array. Then you sort the array in either ascending or descending order, otherwise the principle of the binary search won`t work.

Once you have the sorted array, you can either use the LAbVIEW search array VI or you can implement your own binary search.

Array with elements 0..n, with a target of X.
The Array is passed to a while loop through a non-indexing tunnel as working on a single array without modifications is quickest.
In a while loop you take the middle value (max-min)/2. If this value is greater than your target (assuming the array is sorted in ascending order) then min is set to the current index. If the value is smaller, Max is set to the current index.
Repeat loop until either the item at the current index matches y
our target, or max-min < 2.

If the exact match is not found, your routine must make a choice whether to return the next (higher or lower) item, or return an error with an invalid value.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 5
(6,155 Views)
Shane,
I am using CVI, for some reason the web search dumped me in the LabView(ChildsView) section, but the principle is the same. The sorted array was assumed. Glad you pointed that out. The range(Array) I am working with is a Delay range 0+/-1ns. So my consern is resolution. What is the minimum delay step the BitErrorRate testor can be program to. Basiclly how to end the loop when I have found the max/min Delay that still passes... So I working on this callback. Pass in the delay range min, max, direction(+delay or -delay) and resolution, and return a delay value that is on the edge of the passing delay window. I like the process you mapped. Thanks, Chip
0 Kudos
Message 5 of 5
(6,155 Views)