Had interview today...stumped by a technical question

lonelyt

Member
Mar 16, 2003
79
0
0
Software engineering position.

The interview went well, but there was one technical question I didn't know the answer to.

"What is the Object-oriented way to sort a two-dimensional array?"

I said to use a double for loop (couldn't think of anything), but the interviewer said that way is more of an algorithm....and repeated "What's the best Object-oriented way?"

She told me the answer afterwards (which I still don't really understand), I'll add that in after some replies?

Edit:
The answer: "Use the COMPARE function."
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
"the way is more of an algorithm". What?

I don't even understand the question, to be honest.

Maybe they were referring to the use of a Strategy pattern. That is a pattern and not simply an "algorithm" though. The search algorithm itself varies (that in fact is the point of a Strategy).

Or maybe they were just referring to implementing a Sortable interface...
 

QED

Diamond Member
Dec 16, 2005
3,428
3
0
What exactly does she mean by "sorting" a two-dimensional array?

You can break a two-dimensional array into multiple linear arrays and sort each of those, but you will get different results depending on how you divide the array.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Sounds like a silly question to me. Were they asking about how from a design perspective, or how as in an actual sample implementation? Also, there's no best way to do anything.

I'm guessing they were looking for an answer similar to the following:

Each item in the array would have knowledge of its dimension, and the array would contain those items. When a request to Sort the array was made the items would be iterated and each item would be asked for its sorting order. This has the effect of allowing jagged arrays as well. The key is that this description introduces a level of polymorphism for both array and items contained.

Or I could be way off. Sometimes when someone says, "Tell me in OO" they're looking for more of a description of the design as there's no way to say "show me how you'd implement this in OO" as OO itself has no actual description beyond the language used to implement it.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: torpid
"the way is more of an algorithm". What?

I don't even understand the question, to be honest.

Maybe they were referring to the use of a Strategy pattern. That is a pattern and not simply an "algorithm" though. The search algorithm itself varies (that in fact is the point of a Strategy).

Or maybe they were just referring to implementing a Sortable interface...

Good suggestion. I agree that the question doesn't make much sense; ambiguous, at best.
 

stan394

Platinum Member
Jul 8, 2005
2,112
0
76
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.
 

Gibson486

Lifer
Aug 9, 2000
18,378
2
0
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y


1 2 3
4 5 6
7 8 9
 

stan394

Platinum Member
Jul 8, 2005
2,112
0
76
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.
 

lonelyt

Member
Mar 16, 2003
79
0
0
I was pretty confused by the question too. The answer: "Use the COMPARE function." I pretended like it made total sense because I didn't want to seem like stupid.
 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Originally posted by: lonelyt
Software engineering position.

The interview went well, but there was one technical question I didn't know the answer to.

"What is the Object-oriented way to sort a two-dimensional array?"

I said to use a double for loop (couldn't think of anything), but the interviewer said that way is more of an algorithm....and repeated "What's the best Object-oriented way?"

She told me the answer afterwards (which I still don't really understand), I'll add that in after some replies?

Sounds like she just read a neat little tidbit in a book and couldn't wait to "use" it in the real world.
 

stan394

Platinum Member
Jul 8, 2005
2,112
0
76
Originally posted by: Descartes
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.

huh? why not?
 

five40

Golden Member
Oct 4, 2004
1,875
0
0
Originally posted by: Descartes
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.

hehe. Time to go to back $100 cups of coffee for you.
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
What the hell kind of question and answer is that? What kind of development did they do? What tools/langs did they use? I would of told her that question is too open ended to bother and went home. I've turned down a few jobs do to interviews I had. Of course maybe thats why i'm still only a level 2 programmer.
 

Gibson486

Lifer
Aug 9, 2000
18,378
2
0
just be thankful you can do stuff like a quicksort. I have no idea how to do them. I remember they asked me that in an interview and i just gave them a blank stare. It was at that point i decided to be an EE and stick to minor script coding.
 

five40

Golden Member
Oct 4, 2004
1,875
0
0
I'm guessing the answer they wanted would be...if the object being used has a two-dimensional array sort method, then use that method, otherwise you'd have to write a sort method into the object class
 

DAGTA

Diamond Member
Oct 9, 1999
8,172
1
0
Originally posted by: Descartes
Originally posted by: stan394
Originally posted by: Gibson486
Originally posted by: stan394
what does 'sorting a 2-dimension array' mean? i mean, i had a hard time picturing what is supposed to be the 'right' behavior.

you have an X and a Y

hm.. let's say you have this 2-dimensional array

3 8 7 5
1 2 5 3
6 4 9 7

what does it look like after you sort it?

That's not a 2-d array.

Oh really?