LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (9/3/2009)

Today I'll throw out a VI that I happened to discover on a random walk through the palettes.  The VI is "Search Ordered Table.vi".  Is it just me, or is it vaguely similar to the "Threshold 1D Array" function (only slightly less functional)?  Is there something we should know about one or the other?   If you check that it returns an integer index, perhaps you have an efficient search method for a sorted array.

 

Groundrules for VIOTD here

Message 1 of 17
(4,074 Views)

I believe that threshold array does a linear search, finding the first threshold, while search ordered table does a binary search (after some poorly explained hunting phase, which I don't quite "get"). A binary search is significantly faster for very large arrays, but requires a sorted array.

 

(For a related discussion, see also my suggestion here, and vote for it if you like it :))

 


Now, let's see who can figure out what's wrong with the icon:

 

 

Presumably, the picture shows four array values as a function of the array index. Obviously, the array shown is incorrect, because the first element is higher than the second, in direct contradiction to the requirement that the function needs a sorted array input. 😮

 

(I'll report this in the bug thread...)

Message 2 of 17
(4,046 Views)
I think you have the same two types of sorting in .NET, too.
Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 17
(4,038 Views)

should they not be ordered in size from smallest to largest (# of elements)?

The icon surely does not depict that..

0 Kudos
Message 4 of 17
(4,023 Views)

I also had a hunch that threshold array was not doing what (I think) it should.  Why would you go out of your way to require a sorted input array just to turn around and perform a linear search?  Might as well simply return the first match.

 

I like the suggetion of a binary search function, even if it is separate.  I am waiting to vote for it until I make peace with the idea of '-1' being used to signify no match... Smiley Happy

 

Bonus question now:  What happens in both cases when you input a non-sorted array?

0 Kudos
Message 5 of 17
(4,017 Views)
I don't like the name. Is says "Ordered Table". Technically, in LabVIEW tables are 2D, not 1D, so a more correct name for the VI would be "Ordered Array" or "Ordered List". That's my nitpick for the day.
Message 6 of 17
(4,000 Views)

Darin.K wrote:

I also had a hunch that threshold array was not doing what (I think) it should.  Why would you go out of your way to require a sorted input array just to turn around and perform a linear search? 


Threshold array does NOT require a sorted input, but it will only find the first place after "index" where the threshold  is reached. This, together with the index input allows for some fancy and useful code.

 

Here's one old example how it could be used.

 

 

ALSO:

I suggest to get rid of search ordered table and instead allow an "array is sorted" boolean input for threshold array, similar to my suggestion for search array. (stay tuned for another idea post ;)). It would avoid duplicate functionality. Search ordered table is relatively uselesslimited anyway, because it only supports DBL.

 

An enhanced "threshold array" would work for everything, eliminating duplicate tools such as "sort ordered table".

Message Edited by altenbach on 09-03-2009 11:43 AM
Message 7 of 17
(3,973 Views)

Darin.K wrote:

I am waiting to vote for it until I make peace with the idea of '-1' being used to signify no match... Smiley Happy


I guarantee you that you will get strong opposition if you would suggest to get rid of the "-1" to signify the absence of an answer. It's everywhere!!! 😄

 

I32 does not have NaN! What do you suggest? Make the output an array with zero or one I32 elements? Empty array for "not found"? Add an error output that goes high for "not found"? Not satisfactory!

 

 

Message Edited by altenbach on 09-03-2009 11:57 AM
0 Kudos
Message 8 of 17
(3,955 Views)

altenbach wrote:

Darin.K wrote:

I also had a hunch that threshold array was not doing what (I think) it should.  Why would you go out of your way to require a sorted input array just to turn around and perform a linear search? 


Threshold array does NOT require a sorted input, but it will only find the first place after "index" where the threshold  is reached. This, together with the index input allows for some fancy and useful code.


 

An enhanced "threshold array" would work for everything, eliminating duplicate tools such as "sort ordered table".

Message Edited by altenbach on 09-03-2009 11:43 AM

 
Require is probably the wrong word, I was just pointing out the ominous warning in the help:
Note  Use this function only with arrays sorted in non-descending order.
I assume you meant "Search Ordered Table", "Sort Ordered Table" would be an interesting VI.  Better not use "Quicksort" I seem to remember that a sorted array is a worst-case-scenario for the simple implementations.Smiley Very Happy
0 Kudos
Message 9 of 17
(3,952 Views)

Darin.K wrote:

I assume you meant "Search Ordered Table",...


Yup. 🙂

0 Kudos
Message 10 of 17
(3,939 Views)