Question: Write a program (C/ C++) to construct a graph with three types of nodes organized into three layers as follows: a) Number of nodes in
Write a program (C/ C++) to construct a graph with three types of nodes organized into three layers as follows:
a) Number of nodes in Layer_1 = 10
b) Number of nodes in Layer_2 = 20
c) Number of nodes in Layer_3 = 40
a) Each node in Layer_3 connects to exactly 2 nodes in Layer_2
b) Each node in Layer_2 connects 3 to 5 nodes in Layer_3
c) Each node in Layer_2 connects to exactly 2 nodes in Layer_1
d) Each node in Layer_1 connects 3 to 5 nodes in Layer_2
Note: There is no direct connection between Layer_1 and Layer_3.
Sample Output:
Consider the number of nodes in Layer 1, 2 and 3 are 3, 5, 8 (with same connection constraints).
Layer 1 to Layer 2:
A1 -> B1, B2, B3 A2 -> B1, B2, B3, B4
A3 -> B2, B3, B4, B5
Layer 2 to Layer 1:
B1 -> A1, A2 B2 -> A2, A3 B3 -> A1, A2
B4 -> A1, A3
B5 -> A2, A3
Layer 2 to Layer 3: B1 -> C1, C2, C3, C4, C5
B2 -> C1, C2, C3, C4, C5
B3 -> C3, C4, C5, C6, C7
B4 -> C3, C4, C5, C7, C8
B5 -> C1, C2, C6, C7, C8
Layer 3 to Layer 1:
C1 ->B1, B3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
