A, B).adj_list = {
'A': ['B'],
'B': ['C', 'E'],
'C': ['E'],
'E': ['D'],
'D': []
}
Visual Representation:
A → B → C → E → D
↳ → → → ↑
[('A', 'B'), ('B', 'C'), ('B', 'E'), ('C', 'E'), ('E', 'D')]).(source, destination):
source to the adjacency list if not present.destination to source's neighbor list.destination to the adjacency list if not present (to include isolated nodes).def build_adjacency_list(edges):
adj_list = {}
for src, dest in edges:
if src not in adj_list:
adj_list[src] = []
if dest not in adj_list:
adj_list[dest] = []
adj_list[src].append(dest)
return adj_list