VMWare Inc Interview Question for Software Engineer / Developers






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

It doesn't matter.It isn't a binary search tree.

- bogdan.cebere October 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

HashMap<Integer, BNode> map = new HashMap<Integer, Node>();
BNode p, c;
for (int i = 0; i < a.length; i++) {
if (!map.containsKey(a[i]))
p = new BNode(a[i]);
else
p = map.get(a[i]);
if (!map.containsKey(i))
c = new BNode(i);
else
c = map.get(a[i]);

if (p.left == null)
p.left = c;
else
p.right = c;
c.parent = p;
map.put(a[i], p);
map.put(i, c); //here may use clone()???
}

and add the case of root at the beginning of for loop, like assuming a[i]=-1 => i is the root. may record this node and return it at the end of the method

- Danielle February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's not an array...

- Anonymous December 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If such array is given How to decide whether 'c' is a left child or right child of 'p'?

- Aditya October 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

If it is less than the parent then it is the left child . Otherwise it is right child. since it is a Binary tree..

- hari March 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@aditya..
m also having d same doubt..
may b we cn take any order..

- manni October 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes I think

- Aditya October 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if it doesn't matter then
FOR FIRST case:
make two arrays
c1 and c2 and initialize elements with null;

for( i = 0 to numelments )
if( a[c] ){
if( c1[p]!=null) c1[p]=c
else if(c2[p]!=null) c2[p]=c;
}
}

search for p suct that a[p] is not defined
choose this node as root.
Now you have child information at hand for each node Simply we can apply DFS
OR BFS to make the tree while traversing.

- Aditya October 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what?? I think the program does nothing since, you initialise c1 & c2 to NULL, therefore, none of the "if or elseif" condition is gonna be true ever. correct me if m wrong

- rocks August 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think all you need to do is to walk through the array and create two nodes - one for child and one for parent. Of course you check first if the elements already exist. Create a hash table to quickly check the existence of the elements. Once you have pointers to parent and child nodes, simply associate left or right child based on the value i > a[i].

- Anonymous February 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Hash values in hash table, chain in increasing order of index i.e. a[i]=p, a[j]=p hash is done as Hash[p]--> i---> j such that i < j
2. make root
3. root->left= Hash[root->data]-->first element in chain (i)
4. root->right=Hash[root->data]--->second element in chain (j)
5. repeat

- mgatuiet September 21, 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