PYTHON ALGORITHM…AGAIN.(Depth first search(Dfs))

def dfs(graph, node,   path=[]):path += [node]for n in graph[node]:if n not in path:path = dfs(graph, n, path)return pathgraph = {'A':['B', 'C', 'D'],'B':['A', 'E'],'C':['A', 'F'],'D':['A', 'G', 'H'],'E':['B'],'F':['C', 'I', 'J'],'G':['D'],'H':['D'],'I':['F'],'J':['F']}print(dfs (graph,'A'))
:P

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Using VSCode and Gradle for z/OS Java Development

Advanced Random Sampling in BigQuery SQL

How OneDrive Will Make Your Microsoft Team Migration Easier

SECNOLOGY and the bright value of cloud SIEM & SOAR

GoLang: Send throttled alert mails or notify on Microsoft teams when an error occurs in Go app

8254 A Programmable Interval Timer

Traits over Interfaces

Cracking the Low Level Design (LLD) Interview

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Che Kai LIANG

Che Kai LIANG

More from Medium

Python Packages — A beginners guide

The Minion Game with Python

Hackerrank — Reverse Linked List walkthrough #Python #Hackerrank

LC 53 / maxSubArray (easy)