Chapter 37: Graphs Challenges

Challenge 1

Write a method to count the number of paths between two vertices in a directed graph. The example graph below has 5 paths from A to E:

  • 思路: 利用DFS

Challenge 2

Vincent has three friends, Chesley, Ruiz and Patrick. Ruiz has friends as well: Ray, Sun, and a mutual friend of Vincent’s. Patrick is friends with Cole and Kerry. Cole is friends with Ruiz and Vincent. Create an adjacency list that represents this friendship graph. Which mutual friend do Ruiz and Vincent share?

  • 思路: 就利用AdjacencyList畫出來觀察

Last updated