Question
what is the total/ OVERALL COMPLEXITY of this code : #https://github.com/anxiaonong/Maxflow-Algorithms/blob/master/Ford-Fulkerson%20Algorithm.py import time #________________________ford-fulkerson Algorithm---->dfs(stack,adjacency array)______________________ # class Graph: # def __init__(self, graph): # self.graph
what is the total/ OVERALL COMPLEXITY of this code :
#https://github.com/anxiaonong/Maxflow-Algorithms/blob/master/Ford-Fulkerson%20Algorithm.py import time
#________________________ford-fulkerson Algorithm---->dfs(stack,adjacency array)______________________
# class Graph: # def __init__(self, graph): # self.graph = graph # residual graph # self. ROW = len(graph) # # self.COL = len(gr[0]) def dfs(C, F, s, t): stack = [s] paths = {s: []} if s == t: return paths[s] while (stack): u = stack.pop() for v in range(len(C)): if (C[u][v] - F[u][v] > 0) and v not in paths: paths[v] = paths[u] + [(u, v)] if v == t: return paths[v] stack.append(v) return None
def max_flow(C, s, t): n = len(C) F = [[0] * n for i in range(n)] path = dfs(C, F, s, t) while path != None: flow = min(C[u][v] - F[u][v] for u, v in path) for u, v in path: F[u][v] += flow F[v][u] -= flow path = dfs(C, F, s, t) # print(path) return sum(F[s][i] for i in range(n))
c = [[0 for i in range(5000)] for j in range(5000)]
def loadGraph(): my_file = open("/Users/elaff//Algorithm/project/networkdata.txt", "r") for number in my_file: number=number.strip() nums=number.split("\t") row=int(nums[0].strip())-1 col=int(nums[1].strip())-1 c[row][col]=float(nums[2].strip()) loadGraph() s = 0 t = 90
start3 = time.perf_counter() max_flow_value = max_flow(c, s, t)
print ("Maximum flow: ",max_flow_value) end3 = time.perf_counter() #o(1) print("time: ",end3 - start3) # o(1)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started