morgan stanley IT interview

I went to take part in morgan stanley IT interview this Friday afternoon in Bund Center. I wear my father's suit and tie and shoes bought last night for the interview,which me feel uncomfortable.

 

The interview began with a paper test. two questions. first one is a BST problem. Given a integer N and build a BST whose nodes' keys are 1~N. The tree must be full balanced and have a good structure.eg, it N=7 then the tree is like this:

      4

  2       6

1  3   5   7

And when we should do is to build this tree. Given a N, we should build a tree and store it in the array tree[1...N].

And the tree[i] means the parent node of node i. for example, in the above tree, tree[1] = 2 which means the parent node of node 1 is node 2.

this problem is a little bit different from usual BST problem. it fill the array tree[] with nodes' parent instead of nodes themselves. A little bit weird i spent much time on understanding the problem. And once I know what's the problem requirement I think it is a very easy problem and I can figure it out successfully.

 

 

the second problem is do biginteger multiplication. it is not very difficult problem but very complicated which requires me think about many details.

 

After paper test there are three interviewees who have interview with me one by one. I did a very bad job in the interview because they always asked me questions about java which i am not very familiar. I don't know the reason. I told them i am very familiar with c/c++ and linux and have some basic knowledge about java. But there are two questions about linux and algorithm i think is very valuable for me to remember.

 

Question one:why we cannot create a hard link for a directory on linux.

hard link on linux is a a shortcut which points to the same inode with the original file. If we create a hard link for a directory then it is possible to lead to cycle problem in the link chain.

eg:

mkdir a;

cd a;

mkdir b;

ln ../a b

after the procedure.there exist a cycle in the link chain. directory b under directory a is a hard link to directory, which means: a->b->a-b->a....,which cause infinite loop. and this is why linux prohibit user to create a hard link to a directory.

 

Soft link has different inode with original file. the actual content of soft link store the file name of original file soft link points to. but why can we create a soft link to a directory,which still can cause infinite loop in the filesystem. it is because file system can deal with soft link in a specific way such as limiting the times of loop. if the times of loop is greater than 8 then it stops loop.

 

Question two:how to calculate time complexity of fibonacci recursive formula:

question description: there are ten floors on the ground and a ball can jump to the floors. it can choose jump one floor a time or jump two floors a time. question is how many ways the ball can use to jump to the ten floors.

it is my first time to see this problem and cannot find any good idea about it. the interviewee told me to start with floor = 1. and then floors=2,3,4,...10. then i knew the answer. it is a fibonacci order. the recursive formula is :

T(1)=1,T(2)=2,T(n)=T(n-1)+T(n-2),n>2.

then the interviewee asked me about the time complexity of the algorithm.

the time complexity of algorithm can be calculated by recursive formula:

T(n)=T(n-1)+T(n-2)+1. The formula means the time complexity of T(n) is the time to deal with subproblem T(n-1), T(n-2) and combines the results of two subproblem together(which 1 in the formula represents).

we can expand this recursion formula like this:

T(n)=T(n-1)+T(n-2)+1=T(n-2)+2T(n-3)+T(n-4)+2=T(n-3)+3T(n-4)+3T(n-5)+T(n-6)+4=....=T(n-k)+a(n-k-1)+...T(n-2k)+2^(k-1). let n = k+1 then T(n)=2^n. so we got the final result for the time complexity of the alogrithm is about O(2^n). Although the method is not very accurate but it can get the approximate result. The precise deduction can be found in <introduction to algorithm>.

 

From this two questions which are not very difficult and very basic I know Morgan Stanley likes to test interviewers' basic computer science knowledge. sometimes when i read books and think something is very easy then neglect them, which causes my misunderstand of them. I should be more patient and more precise in the future study.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值