Graph algorithms demystified #1

Simplest way to model a Graph or Tree

Photo by Nick Fewings on Unsplash
person ---(knows)---> person
if A knows B it does not mean that B knows A
Map[String, List[String]]
val PeopleInTheRoom: Map[String, List[String]] = Map(
"Jane" -> List("Bob", "Mark", "Rajesh", "Samanta", "Hussein"),
"Mark" -> List("Tom"),
"Bob" -> List("Lisa", "Jenny"),
"Tom" -> Nil,
"Lisa" -> Nil,
"Jenny" -> Nil
)
val binaryTree: Map[Int, List[Int]] = Map(
5 -> List(4, 2),
4 -> Nil,
2 -> List(0, 3),
4 -> List(-1)
)

I am a Software Engineer 👨‍💻 that works remotely, builds his own projects, and shares the journey online