Microsoft Interview Question for Software Engineer / Developers






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

Lets say we have m x n matrix.

In row-major order we have
to access (i,j) we have ((i * no_of_col) + j).
we have ((i * n) + j) in our case.

In col-major order we have
to access (j,i) we have ((j * no_of_row) + i).
we have ((j * m) + i).
since (i,j)th element in row-major form is the same as (j,i) in col_major_order and m x n will now be n x m.

so equating we have ((i * n) + j) = ((j * m) + i)
we get ni + j = mj + i i.e i / j = (m - 1)/(n -1).


Can somebody please verify this.

- takeiteasy June 24, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you give an example of what you're talking about? I don't understand. Thanks!

- Khoa August 20, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Khoa,

You would be knowing that any n-dimensional matrix (array) finally boils down to a sequential representation in memory.

Eg.:

a[0,0] a[o,1]
a[1,0] a[1,1]

would be stored as:

1-D Index 0 1 2 3
Address: 1000 1002 1004 1006
Item: a[0,0] a[0,1] a[1,0] a[1,1]

which is row major order.

Here, a[1,0] = a[2] (not literally, but in memory)

So, the Q was to write a general expression to represent this relation for both row and column major order representations of an array.

I hope this clarifies. Sorry, I typed the Q in a hurry so, it is ambiguous.

- P August 23, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I misinterpreted the question. Thanks!

- Khoa August 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for row major

((no. of columns *i) +j)

where i=row no
j=colomn no

- shan August 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

http://en.wikipedia.org/wiki/Row-major_order

- Manish August 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you want to find the actual position in the memory -

Location in memory - rownum * nocolumns * bytes + columnnum *bytes

Where bytes = No of bytes required to store that variable. E.g. int is 4 bytes, char is one byte etc.

- Anonymous February 23, 2007 | 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