I am learning Python with existing internet projects, I need help getting the output of this algorithm

”’I am learning Python with existing internet projects, the code belongs to an algorithm to find out the number of connections. I ask for help since I have not been able to obtain the output of the algorithm
starting @ airport LGA
The following airports are unreachable
BGI
CDG
DEL
DOH
DSM
EWR
EYW
HND
ICN
JFK
LHR
ORD
SAN
SFO
SIN
TLV
BUD
[(‘EYW’, 7), (‘LHR’, 7), (‘SAN’, 7), (‘SFO’, 7), (‘TLV’, 6), (‘DEL’, 5), (‘EWR’, 4), (‘CDG’, 3), (‘DSM’, 3), (‘HND’, 3), (‘SIN’, 3), (‘ICN’, 2), (‘ORD’, 2), (‘BGI’, 1), (‘DOH’, 1), (‘JFK’, 1), (‘BUD’, 1)]
”’

airports = [“BGI”,”CDG”,”DEL”,”DOH”,”DSM”,”EWR”,”EYW”,”HND”,”ICN”,”JFK”,”LGA”,”LHR”,”ORD”,”SAN”,”SFO”,”SIN”,”TLV”,”BUD”,]
routes = [[“DSM”, “ORD”], [“ORD”, “BGI”], [“BGI”, “LGA”], [“SIN”, “CDG”], [“CDG”, “SIN”], [“CDG”, “BUD”], [“DEL”, “DOH”], [“DEL”, “CDG”], [“TLV”, “DEL”], [“EWR”, “HND”], [“HND”, “ICN”], [“HND”, “JFK”], [“ICN”, “JFK”], [“JFK”, “LGA”], [“EYW”, “LHR”], [“LHR”, “SFO”], [“SFO”, “SAN”], [“SFO”, “DSM”], [“SAN”, “EYW”]]
startingAirport = “LGA”
”’
class AirportNode:
def init(self, airport):
self.airport = airport
self.connections = []
self.isReachable = True
self.unreachableConnections = []

def airportConnections(airports, routes, startingAirport):
## build a graph for airports and connections
airportGraph = createAirportGraph(airports, routes)
## find unreachable airports/Nodes
print(“starting @ airport “, startingAirport)
print(” The following airports are unreachable”)
unreachableAirportNodes = getUnreachableAirportNodes(
airportGraph, airports, startingAirport
)
for u in unreachableAirportNodes:
print(u.airport)
## assign a score for each airport of the unreachables
markUnreachableConnections(airportGraph, unreachableAirportNodes)
## now return minimum number of connections
return getMinNumberOfNewConnections(airportGraph, unreachableAirportNodes)

O(a + r) time | O(a + r) space

def createAirportGraph(airports, routes):
airportGraph = {}
for airport in airports:
airportGraph[airport] = AirportNode(airport)
for route in routes:
airport, connection = route
airportGraph[airport].connections.append(connection)
return airportGraph

O(a + r) time | O(a) space

def getUnreachableAirportNodes(airportGraph, airports, startingAirport):
visitedAirports = {}
depthFirstTraverseAirports(airportGraph, startingAirport, visitedAirports)

unreachableAirportNodes = []
for airport in airports:
    if airport in visitedAirports:
        continue
    airportNode = airportGraph[airport]
    airportNode.isReachable = False
    unreachableAirportNodes.append(airportNode)
return unreachableAirportNodes

def depthFirstTraverseAirports(airportGraph, airport, visitedAirports):
if airport in visitedAirports:
return
visitedAirports[airport] = True
connections = airportGraph[airport].connections
for connection in connections:
depthFirstTraverseAirports(airportGraph, connection, visitedAirports)

O(a * (a + r)) time | O(a) space

def markUnreachableConnections(airportGraph, unreachableAirportNodes):
for airportNode in unreachableAirportNodes:
airport = airportNode.airport
unreachableConnections = []
depthFirstAddUnreachableConnections(
airportGraph, airport, unreachableConnections, {}
)
airportNode.unreachableConnections = unreachableConnections

def depthFirstAddUnreachableConnections(airportGraph, airport, unreachableConnections, visitedAirports):
if airportGraph[airport].isReachable:
return
if airport in visitedAirports:
return
visitedAirports[airport] = True
unreachableConnections.append(airport)
connections = airportGraph[airport].connections
for connection in connections:
depthFirstAddUnreachableConnections(
airportGraph, connection, unreachableConnections, visitedAirports
)

O(alog(a) + a + r) time | O(1) space

def getMinNumberOfNewConnections(airportGraph, unreachableAirportNodes):
## loop over unreachableconnections starting with those with the highest number of unreachable connections
## increment newconnections number but mark all those unreachable connections as reachable (by virtue
## of connecting the representative unreachable connection)
unreachableAirportNodes.sort(
key=lambda airport: len(airport.unreachableConnections), reverse=True
)
print([(i.airport, len(i.unreachableConnections)) for i in unreachableAirportNodes])
numberOfNewConnections = 0
for airportNode in unreachableAirportNodes:
if airportNode.isReachable:
continue
numberOfNewConnections += 1
for connection in airportNode.unreachableConnections:
airportGraph[connection].isReachable = True
return numberOfNewConnections

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật