Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[PYTHON] Given a connected computer network (bidirectional communication) we wan

ID: 3598635 • Letter: #

Question

[PYTHON] Given a connected computer network (bidirectional communication) we want to find two different nodes u and v such that we can maximize the congestion between u and v with a continuously sent virus being sent between the pair. We define the congestion level as the maximum number of edge-disjoint paths between nodes u and v. For example, the network shown in the following figure has three different paths between nodes 0 and 6 such that each edge is only part of one of the paths. Note that two paths are allowed to go through the same node, such as node 7. No other pair of nodes has a higher congestion level.

We will be given a sequence of connected computer networks each with n nodes, n 40, labeled {0, 1, ..., n1}. The last input case will be followed by a network of n = 0 nodes, which should not be processed. The specification for a computer network will be as follows: the first line contains a single non-negative value n, denoting the number of nodes. This is then followed by n lines of integers, separated by spaces, denoting the neighbors (zero indexed) of each node. Expect up to 2000 test cases.

For each input case output one integer on a line by itself denoting the maximum congestion level possible for some pair of its network nodes.

Sample Input

8

4 5 7

5 6

6 7

7

0 7

0 1

1 2 7

0 2 3 4 6

4

1 2

0 2

3 0 1

2

0

Output for Sample Input

3

2

Provide the code in python (NetworkX permitted).

6 2 1 5 7 0 3

Explanation / Answer

Bidirectional search:

In normal Breadth first search/ Depth first search(BFS/DFS) we begin our search in one direction from root node(source node) to target node(destination node)

In Bidirectional search we search from both directions simultaneously. That is

Forward search from source node to destination node and

Backward search from destination node to source node. Bidirectional graph replaces the normal single search in to two smaller sub graphs. The search stops when the two graphs intersects.

Advantages: Bidirectional search has reduced time complexity of 0( bd/2).

In this problem, we are going to apply the concept of Bidirectional search using BFS to find the maximum congestion control.

The maximum path of each node can be found in the following ways.

a) Any node(node only)

b) maximum path through the left child+ selected node

c) maximum path through right child+selected node

d) maximum path through left child+selected node+maximum path through the right child node.

Here we have to follow the four paths and choose the maximum path at the end.

Python code:

class node :

def_initate_(weight, data):

weight.data=data

weight.left=none

weight.right = none

def findmaxcon(rootnode) : //this function returns the maximum congestion going through root node

if rootnode is none:

return 0

le=findmaxcon(rootnode.left) //left stores maximum congestion sum going through left child of root.

ri=findmaxcon(rootnode.right) //right stores maximum congestion sum going through right of root.

//This part is important

// The root of every subtree must return the maximum congestion sum in such a way that at the maximum one child of root is involved.

max_one=max(max(le,ri)+rootnode.data, rootnode.data)

maxtopnode=max(max_one, le +ri+rootnode.data) //maxtopnode represents the sum when the selected node is the root of the maximum path and no parent of root are there in maximum sum path.

findmaxcon.result= max(findmaxcon.res, maxtopnode) //stores the maximum result among the two in the findmaxcon.result

return max_one

def findmax_sum(rootnode)://used to defing the maximum sum with given root

findmaxcon.result=float("-inf")

findmaxcon(rootnode)

return findmaxcon.res //returns the result

rootnode =node(1)

rootnode.left=node(5)

rootnode.right=node(6)

rootnode.left.left=node(0):

rootnode.left.left.right=node(4);

rootnode.right.right=node(2);

rootnode.right.left=node(7);

rootnode.right.left.left=node(3);
print "The maximum congestion path sum is ", findmax_sum(rootnode);

  

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote