Question: 1 ) Create a network with exactly 1 0 0 different paths from node 1 to node n . You can choose yourself what n

1)Create a network with exactly 100 different paths from node 1 to node n. You can choose yourself what n is and which arcs are in the network.
Number of paths is 100.
Write the python algorithm that creates the net:
2)Given a directed acyclic network with python, your task is to count how many different paths there are in the network.
Implement a class AllPaths with the following methods:
add_edge adds an arc between two nodes
count gives the number of different paths
Implement method count efficiently with dynamic programming.
Implement the class in the file allpaths.py as shown in the following example.
class AllPaths:
def __init__(self, n):
# TRUE
def add_edge(self, a, b):
# TRUE
def count(self):
# TRUE
if __name__=="__main__":
a = AllPaths(4)
a.add_edge(1,2)
a.add_edge(1,3)
a.add_edge(2,4)
a.add_edge(3,4)
print(a.count()) # 10
a.add_edge(2,3)
print(a.count()) # 14
Explanation: The first call of the count method counts the following paths:
1
1->2
1->2->4
1->3
1->3->4
2
2->4
3
3->4
4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!