National Instruments Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

For shuffling ,better we can use hash array,do hashing with some mathematical operation,
like (card_value+7)%10 ,then the all cards will be shuffled.

- midhun sukumaran February 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What the hell is wrong with you? Why do you have to post the same question multiple times?

- Anon September 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a linked list containing all cards in order.
1. split the list
2. insert elements from list B into list B alternately

The problem now breaks down into: whats the best way to split a list, and how do we insert alternately.
This will ne O(n), but the shuffling would be pretty guessable.

We can also use a treap. Pick a card (for loop), assign a priority to it, maintain heap property on the random priorities.
This would be nlog n to create the treap, and log n to de-heap each element and place them back in the pack.
For pseudo-random priorities the shuffling would be less predictable than the linked list.

Actually the easiest would be a 52 slot hash table with random numbers as card indices.

- Anonymous October 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use array and then following algorithm

Let X1, X2…. XN (In this case N=52) be the set of N numbers to be shuffled.

1 Set j to N
2 Generate a random number R. (uniformly distributed between 0 and 1)
3 Set k to (jR+1). k is now a random integer, between 1 and j.
4 Exchange Xk and Xj
5 Decrease j by 1.
6 If j > 1, return to step 2.

- Swapnil December 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use array[52] of objcets for storing the cards. Where object will be of type card having various poperties like (color, type <heart, diamond, ....>) ......

Now for shuffuling we need to use trick :
First genarate any random number using rand() function. This will ensure that number will not same at each time.
The use shift/rotate operation on our cards array like rotate(array, rand())
This rotate function will just rotate each element from array to the right or left (your choice) to the random number genarated.

- santosh diwase March 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks for the answer!

- Rohini May 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey thanks for the answer

- Rohit July 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks!

- aashish March 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use and array to store the cards. I'm assuming you deck of cards will not grow so you don't need a linked list and if it did grow you could still allocate a larger array and copy the values there however this would take more work than a linked list.

int cards[NUM_CARDS];
fill cards array with cards

Anyway shuffle()

for (i = 0; i < NUM_CARDS; i++)
int newLoc = rand() % NUM_CARDS;
temp = cards[i];
cards[i] = cards[newLoc];
cards[newLoc] = temp;


You are going to shuffle without any space increase and only n time. Some cards may stay in the same place because you may have swapped them back and forth. I assumed this was alright. Every card will be touched.

- taylor.grimes.cs September 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use array of objects as santosh said. For shuffling, we can use Knuth's shuffle method. Which is a simple iteration through the array while choosing a random number from remaining elements and change it with current position.

- Soham November 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think there are different ways to shuffle cards, to make sure every card is shuffled, we can go through the array, and replace array[i] with array[i+1 mode n], and change the shuffle flag to True. Or we can use Knuth's shuffle algorithm to generate a random number proportional to the size of the remained unshuffled array.

- mohammad.dibay April 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use a circular queue and randomly shift the head pointer i.e we can use a rand() function to move the head pointer from current to anyside by a random distance and then we can start moving in clockwise or anti-clockwise direction

- spkr322 October 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is an interesting one. A simple array can solve this problem. Loop 52 times (for all the card nos.) and swap each card (arr[i] with any random number i.e. arr[random] where you have chosen a random number from (i,51). This will give you a perfectly shuffled deck and that too in O(n) time:)

- mitshubh October 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am an IT Recruiter looking for some Software Engineers in the Austin area contact me directly--client has asked that I recruit specifically for National Instrument Candidates candidates suzie.jimenez@thehtgroup.com 512.345.9300

- suziejimenez3 September 25, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More