Had interview today...stumped by a technical question

Page 5 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

skimple

Golden Member
Feb 4, 2005
1,283
3
81
Originally posted by: torpid


Semantically yes, but in some languages using some weird memory kung fu they actually store 2d arrays as single memory blocks and not in seperate locations. That is why if you traverse the 2d array going vertically instead of horizintally (or vice versa) when sorting, it can be somewhat less efficient.

Nice! :D
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: Descartes
Originally posted by: torpid
Originally posted by: mugs
Originally posted by: Descartes

No, I really didn't choose to do so. My first reaction was erroneous as I was thinking of it differently at the time, I admit it, and now I understand what everyone was saying.

I'll say it: My mistake. Suggesting I don't know what a 2D array is is rather silly, and anyone that knows me should quickly realize that.

Sorry I said that. Your replies here usually display a high level of intelligence, so it surprised me that you were blinded by your first impression and unable to see what the person who posted the array had in mind.

I'm still wondering where you got a fourth dimension from.

I believe he was thinking that the numbers represented a single dimensional array of the size represented by the number...? e.g.

3 1 5
2 3 4

=
Array of size 3, array of size 1, array of size 5.

Eh, who knows. He was clearly thinking too far outside the box. That happened to me once... the new radiohead cd had just come out and someone told me "radiohead sold out" and I was panicking thinking I wouldn't be able to get the CD anywhere.

You are correct. I'm actually taking a moment to think why that was my default thought process, because under normal circumstances it isn't. When I finally realized it I was a little disconcerted to say the least.

I still only see 3 dimensions though. :confused:
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: mugs
Originally posted by: Descartes
Originally posted by: torpid
Originally posted by: mugs
Originally posted by: Descartes

No, I really didn't choose to do so. My first reaction was erroneous as I was thinking of it differently at the time, I admit it, and now I understand what everyone was saying.

I'll say it: My mistake. Suggesting I don't know what a 2D array is is rather silly, and anyone that knows me should quickly realize that.

Sorry I said that. Your replies here usually display a high level of intelligence, so it surprised me that you were blinded by your first impression and unable to see what the person who posted the array had in mind.

I'm still wondering where you got a fourth dimension from.

I believe he was thinking that the numbers represented a single dimensional array of the size represented by the number...? e.g.

3 1 5
2 3 4

=
Array of size 3, array of size 1, array of size 5.

Eh, who knows. He was clearly thinking too far outside the box. That happened to me once... the new radiohead cd had just come out and someone told me "radiohead sold out" and I was panicking thinking I wouldn't be able to get the CD anywhere.

You are correct. I'm actually taking a moment to think why that was my default thought process, because under normal circumstances it isn't. When I finally realized it I was a little disconcerted to say the least.

I still only see 3 dimensions though. :confused:

Me too. Like I said the 4th dimension is time.

 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: lonelyt
Thanks everyone for the responses. Jbourne and Torpid cleared up the interviewer's answer for me, I really had no idea about the compare function you could write into objects. And Descarte's being a good sport, he already apologized for reading it wrong.

:thumbsup:

If you want a specific example of how this might be implemented you can look at .NET's IComparable interface which defines a CompareTo method. The key point is that the objects have the ability to compare themselves relative to another; it's delegating the responsibility of comparison to the items themselves rather than a single sorting method which has all the knowledge of what to sort and how. This is where the OO description comes in, and that's what I thought the question was about.
 

interchange

Diamond Member
Oct 10, 1999
8,026
2,879
136
Originally posted by: jbourne77
Originally posted by: interchange
Derr, from the answer...I think the problem is not asking you to sort them, but how would you determine if one object is greater than another.

If you were sorting, say, ints then it's simple. You use (x < y).

Say we're programming in java. We have two objects, x and y. How would you compare them? if (x.compareTo(y) < 0)... (x < y) would compare their references (like pointers) and wouldn't really tell you much.

That's actually not true. The compare function, IIRC (it's been awhile) would return -1 if the object o1 should appear ahead of object o2, 0 if they were equal, and 1 if it should appear after. This actually is how you would go about sorting them, and properly done, this logic would be contained in the required methods after implementing the Comparator interface.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html#compareTo(T)

I stick by what I wrote. The interface is Comparable, and implementing it makes compareTo a required function. Unlike C++, you cannot overload operators in java.

Maybe you misunderstood what I wrote, but as far as I'm concerned I answered OP's question.