The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

CLAD2017 - Fundamentals - Array Manipulation 2 of 5

SercoSteveB
Active Participant

Which of the following are possible values for Numeric Array Out following execution of the VI? NOTE:  Multiple answers may apply.

 

Array Manipulation Snippet.png

 

Array Manipulation Image.jpg

Comments
crossrulz
Knight of NI

A, B, C, D


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
maccapple
Member

Could not get it why there are 4 answers(comparison gives negative values?). Trying to copy but can not copy snippet on my labview version 17. Any solution for this?

Got it...but still looking for possibilities for copying snippet

crossrulz
Knight of NI

If an element is not in the array, Search 1D Array will return -1 for the index.  So if the item is not found, it will be added to the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
moni11
Member

If the search array returns -1 then it will insert numbers.If the search array is returns greater than 0 then it will be true case and the array will pass as it is without inserting any numbers. If this is true then only A,B,D are the right answers

User002
Not applicable

Whoops, I had agreed with @crossrulz's initial answer (A, B, C, D), but I had misread the ">/=0" as "=0".

 

I now say A, B, D.

 

If it were instead "=0", then [3, 8, 10, 8] would be possible, but [3, 8, 8, 10] would not.

 

-joeorbob

crossrulz
Knight of NI

Well, I'm a little embarrassed now.  I missed the duplicated items (8) in C.  So the answer is A, B, D.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
nik35324
Member

A, B, D

abasak86
Member

It seems B, C and D. An array with single element is not appearing. Already tried in LabVIEW. Kindly suggest.

moni11
Member

A with the single element is possible but not always...

User002
Not applicable

@abasak86 wrote:

It seems B, C and D. An array with single element is not appearing. Already tried in LabVIEW. Kindly suggest.


First, C is not possible. Because of the algorithm, any "repeated" elements will be excluded. C has two 8's, so it is not an answer.

 

 

Next, it *is* possible to get a single element (like answer A), but it is very unlikely. I did a quick probability estimate - I got the probability of a single-element array to be 0.0090625%, or about 1 in 11034.

Spoiler
This assumes an even distribution over the sequence of numbers {0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10}, which is not perfectly accurate, but I think is really close. I'm not a statistician, and if someone else wants to get a better estimate, I would be happy to see it.

That means to reliably get one single-element array, you might need to run the program a LOT. Like, over 10,000 times.

 

Here's my (seemingly successful) attempt. 😄

Spoiler
theDailyCLAD_20200929_repeated_JoB.png

Here's the front panel after a run - I ran it 50000 times and got these single-element arrays. (The number of single-element arrays changes each run, of course, but this was a reasonable spread, which is why I chose this screenshot.)

 

theDailyCLAD_20200929_repeated_FP_JoB.png

 

To conclude, yes, A can be an answer. Just not very often, if you're running the code one array at a time.

 

-joeorbob

Matt-A.
Member

A, B, D

skian
Member

The answer seems A,B and D but in realty the code will not insert even one element into the array, since the search result will always be true at selector input and the original empty array will be returned.

 

In order to gain the desired result , one might connect the Boolean output of search sorted array  to selector  function.

crossrulz
Knight of NI

skian, the search result will NOT be always true.  If you search for a value in an empty array using Search 1D Array, the returned index will be -1.  Now if you search for 4 when the current array is {1}, you will also get a -1 for the returned index.  Both of these situations will result in a FALSE as the Select function, and therefore adding to the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
skian
Member

Crossrulz, Thanks for your reply. I was looking at Search Sorted 1D Array, vs Search Unsorted 1D Array

At a glance the icons look similar but with careful observation, there is an arrow on the former one.😊

 

istan0227
Member

A,B,D