Directi Interview Question for Software Engineer / Developers






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

What exactly does the "center of a tree" mean?

- Anon October 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I wish you were asked a question like this(without any details) in an interview!

- Mahesh October 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think center of the tree is same as center of the graph.
center of the graph.
first delete all the nodes with indegree 1.and corresponding edges...also
repeat deleting nodes with indegree 1 from obtained graph untill one vertex are two
obtained.

- Just October 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for binary tree :
1> find two longest path from root to leaf
2>the center of these two path( go in to the longest path by a distance of the difference of these two path) is the center of the complete tree
and these two( the longest paths) together make the diameter of the tree.

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

It is NOT AT ALL NECESSARY that root falls on the longest path. Try making a tree with 2 longest paths from one of the child nodes. It'd fail.

The whole idea is to find the diameter of the tree, which is the longest path between any two leaf nodes and find the mid point of it.

- Bumblebee April 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@bumblebee
what do you mean by "find the mid point of it"?

- swathi July 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

nice solution ... good assumption of the center.

- anonymous January 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In graph theory, a tree is defined as a graph on N nodes,and (N-1)
un-directed edges such that there are no cycles in the graph.Each node
has a single unique path to every other node.
Let D(u,v) be the number of edges in the unique path from node 'u' to
node 'v' (or from node 'v' to 'u' since the edges are
un-directed).D(u,u) is 0 for all nodes 'u'.
M(u)=MAX(D(u,i):for all nodes i)
The center of a tree is the node (or nodes) 'u',for which M(u) is
minimum among all the nodes in the graph.
You'll be given a graph which has N nodes (1<=N<=20).The nodes are
labeled 1,2,3,..N.You will be provided with N-1 edges in the form of
"a b" pairs where 1<=a,b<=N.No edge will be repeated.You can assume
that the edges are specified such that the graph is a valid tree as
defined above.
Output the node labels of the center(or centers) of the tree.
Sample Input:
6(value of N)
1 3 (edges)
1 4
1 2
2 5
2 6

Sample Output
1
2
Expected:O(N) complexity algo
can anyone plz help me out with O(N) algo?

- Anonymous July 26, 2011 | 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