Amazon Interview Question for Software Engineer / Developers






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

Given a graph G=(V,E)
-Find strongly connected components in G
-Replace each SCC with a vertex, G become a directed acrylic graph (DAG)
-Topological sort on DAG
-If there is an edge between each pair of vertices(v[i],v[i+1]) then the given graph is semi-connected

- hungduongn September 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this should be the correct answer

- tianclch November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 3 vote

Create adjacency matrix with number given to each of the vertices.
Graph is semi-connected
foreach i,j
if(i!=j && (a[i][j] || a[j][i])

- Anonymous September 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

code:
bool isSemiConnected= true;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i==j)continue;
if(!(a[i][j]||a[j][i])){
isSemiConnected = false;
break;
}

- Anonymous September 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Actually adjacency matrix and path matrix are not one and the same. I think we should be using path matrix here and not adjacency matrix.

- Pavan Dittakavi August 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

By definition that cannot be right because you are just taking in account that u->v and not there could be a vertex x such that u->x | x->v ==> u->v

- Anonymous September 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1)create path[][] array based on edge[][].
2)Check whether it is semi-connected.

for(i=0;i<n;i++)DFS(path,i,i);
void DFS(int[][]path,int root,int current)
{
for(j=0;j<n;j++) if(edge[current][j]==1){path[current][j]=1;
DFS(path,root,j);}
}

- anonymous November 16, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It should be==>path[root][j]=1;

- anonymous November 16, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This looks a classic problem of Network Flows: We can take a node at random in the graph and imagine it to be a source which has unlimited flow coming into it, and the corresponding edges can be used to direct the flow of water from this source and to wherever the water comes out we can think of this as the connected nodes and we can remove them from the graph and if there is atleast 1 node left which is not connected we can call it as v now in the orignal graph check if there is a path from v to u, if there exists then it is a semi connected and if there doesn't exist then it is not a semi connected graph.

the running time of this algorithm is O(n square) where n is the number of nodes in the graph.

- SiD January 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can use DFS to check if there are backward edges - happens if you encounter a node that is already visited but not explored. If you are able to traverse through the entire graph without any backward edges then its semi-connected

- geek August 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Backward edge just implies cycle in a graph.. If you consider a binary tree as a graph, then you can traverse the binary tree without encountering back edges.. But, it is not a semi connected graph..

- Anonymous September 22, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i=0 to <n
j=0 to i
if ( a[i][j]&&a[j][i] ) !=1
print not semi connected ; break ;

- Anonymous August 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sry wrong ans ... my bad

- Anonymous August 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hxxp://cs.sunysb.edu/~jgao/CSE548-fall08/homework1-soln.pdf

- find the ans here. December 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can't we solve this using lists similar to adjacency lists. Every node has a list of all its connected nodes. For every vertex v, if u is reachable from v, u will be in the list of v. On the other hand, if v is reachable from u, then, v will be in the list of u. After visiting all the nodes of the graph (using DFS may be), we need to scan each vertex's list & see who is reachable & not. This may require another data structure. Complexity defenitely sucks in this approach.

- Helper December 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool issemiconnected(graph[n][n])
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
  {
     if(i==j)
     continue;
     else
      {if( ! ( graph[i][j] || graph[j][i] )
          {
        return false;
          }
       }
   }
}
return true;
}

- Anonymous June 20, 2013 | 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