Amazon Interview Question
Dev LeadsTeam: RMCC
Interview Type: In-Person
how can i merge 2 nodes in a graph in 1 node , need to save the in and out edges and the nodes that was merged for contribution after that
for example a graph implementation in adj list:
1->3->4->6
2->3->4->6
5->4->6
and i want to merge the nodes 3 and 4 , then new nodes should be created 7 as :
1->7->6
2->7->6
5->7->6
7->6
the node 7 also will save [include 3,4 the merged nodes]
any one can help with that please
the implementation should be in c code.
typedef struct AdjListEntry {
int visited;
int index;
struct AdjListNode current; // node iniformation
struct AdjListEntry* next;
} AdjListEntry;
typedef struct AdjListNode {
int Uind;
char name[10];
char label[10];
adjOutEddgeLists *outEddges;
//adjInEddgeLists *inEddges;
} AdjListNode;
typedef struct adjOutEddgeLists{
AdjListNode *listNode;
adjOutEddgeLists *next;
}adjOutEddgeLists;
how can i merge 2 nodes in a graph in 1 node , need to save the in and out edges and the nodes that was merged for contribution after that
for example a graph implementation in adj list:
1->3->4->6
2->3->4->6
5->4->6
and i want to merge the nodes 3 and 4 , then new nodes should be created 7 as :
1->7->6
2->7->6
5->7->6
7->6
the node 7 also will save [include 3,4 the merged nodes]
any one can help with that please
the implementation should be in c code.
typedef struct AdjListEntry {
int visited;
int index;
struct AdjListNode current; // node iniformation
struct AdjListEntry* next;
} AdjListEntry;
typedef struct AdjListNode {
int Uind;
char name[10];
char label[10];
adjOutEddgeLists *outEddges;
//adjInEddgeLists *inEddges;
} AdjListNode;
typedef struct adjOutEddgeLists{
AdjListNode *listNode;
adjOutEddgeLists *next;
}adjOutEddgeLists;
can u elaborate your question. Do not understand the ask
- Anonymous December 05, 2015