The Daily CLAD

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

Re: CLAD2017 - Answer the Requirement - Searching a 2D Array

SercoSteveB
Active Participant

You are tasked to write a VI that accepts, as inputs, a 2D array of numerical values (Numeric Array In) and a numerical value (Search Value) and outputs two numerical values (Row and Column).  Your VI must search Numeric Array In for occurrences of Search Value and output into Row and Column the row and column of Numeric Array In in which the last occurrence of Search Value was detected. 

 

Which of the following VIs satisfies those requirements?

 

NOTE:  The search algorithm is not mandated but it can only search Numeric Array In once and the values returned into Row and Column must be the row and column of Numeric Array In where your designated search algorithm detected the last occurrence of Search Value.

 

NOTE:  The VI assumes the search value is always in the Numeric Array In.

 

NOTE:  More than one answer may apply.

 

Have a go at coding the VI yourself or expand the Spoiler tag to display the possible answers.

 

Spoiler
a)
Search 2D Array 1.png

b)
Search 2D Array 3.png

c)
Search 2D Array 2.png

d)
Search 2D Array 4.png

 

Comments
kiranteja93
Member

i think C is the answer.

i  think in option A  transposing the 2D array would make the changes in column and row values

in B if search value in present in 0 index it would not show that in which column the Search Value would be presnt.

i do not understand Option D. i think i should try that .  D also not a good option.

 

mini09
Active Participant

C, nice one steve

kiranteja93
Member

sorry folks, D also a good answer.

nik35324
Member

C

Baltur
Member

C

@ kiranteja93 : D seems to work as long as an element is found, but look at what happens when no element is found

nik35324
Member

Check this old post from 

 

Spoiler
kiranteja93
Member

you are right Baltur. thanks for that.

crossrulz
Knight of NI

I would like some more clarification on the question.  Specifically, how is "last occurrence Search Value was detected" defined?  Are we just looking for the last value the search algorithm used found the item?  The last time the value is actually in the array?  Does the row take priority or the column?

 

A will give you the coordinates of the first instance of the search value using the first column the value is in.

B will give your the coordinates of of the first instance starting from the last row.  Problem here will be if there are multiple instances in the same row.

C will give you the coordinates of the first instance starting with the first row.

D will work at long as the search value is actually in the array.

 

Only C actually properly handles if the value was not found (return -1, -1).

 

So in my opinion (pending the clarification), none of the above meet the requirements with proper error handling.


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
SercoSteveB
Active Participant

All good points, well made.  It made sense to me when I wrote it.  Smiley Frustrated 

 

The search algorithm is not mandated, you can search in any direction you like and in any row/column order you like.  You have a free hand as long as you don't change the search direction mid way through and that you only search through the array once.  You are looking to return the row and column for last element with Numeric Array In that your search algorithm detected the Search Value

 

Think I bit off more than I could chew with this one. Smiley Mad

 

NOTE:  I have added an assumption to the question (to avoid having to change my snippets)

crossrulz
Knight of NI

Well in that case:

  • they all detect a value correctly
  • they all return the last value it found

So all the above!


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
Baltur
Member

After Steve's clarification post and the newly added assumption that the searched value is always in the array:

A, C and D meet the requirements

B does return the last found value, but it will return multiple positions if the searched value is present in multiple line. (It can find maximum one value per row, so it won't detect all positions if the searched value existis multiple time within the same row) 

crossrulz
Knight of NI

B just will not detect the multiple items in a row.  But per Steve's definition, this fine since that is how the search algorithm was done.  However, I just noticed that the condition for the indexing tunnel is using >0, which means if the item is in the first column (index 0) it will not be included in the array.  It should be using >=0.


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
Tianming
Member

B is the only right one. A C D returns the first one the algorithm detected.

Priya16
Member

In this above question we must clarify following requirements for our clearance we can split into three cases

Case 1: if the search value is in numeric array in (no more repeated values) then option A,C,D would satisfy the requirements.

(Option B could not satisfy the requirement because of greater than zero condition)

Option A: even though transpose array is placed outside, the row & column numeric indicators position is interchanged so that satisfies the requirement.

Option C & 😧 without no doubt satisfies the requirement.

Case 2: if search value is available

more than one time in numeric array in then we should remind the last occurrence of search value so that option D 

(Option A & C returns the first occurrence of search value)

Option B: it returns the last occurrence of search value because mainly row & column is connected to deleted portion. So before last occurrence of search value the remaining returns in subset deleted. But it fails in the case of multiple times search value available in same row

Option 😧 Because of reverse 1D array it would return last occurrence of search value

Case 3: If the search value is not available in numeric array in then option C only appropriate answer. Because it would return -1, -1. Its not make any sense -1 row & column.

Option A: returns n-1 index row & column

Option B: returns default value(0) 0 row & column

Option C: results wrong calculation of row & column because search 1D array would return -1 if value is not in numeric array in

SercoSteveB
Active Participant

Answer:  Not sure.  Pretty good conversations though, nice one.