Skip to content

πŸ… Beginner diploma

Yehonathan Sharvit edited this page Jul 12, 2021 · 13 revisions

🀝 A social graph

Your mission is to create a social graph and to write functions that answer questions about the social graph:

  1. Are two members friends?
  2. What's the average number of friends?
  3. Given two friends, calculate how many friends they have in common
  4. BONUS: Are two members connected through a friendship path (Dijsktra algo might help)?

Also, please write functions that change the graph, without using any atoms:

  1. Add a member
  2. Remove a member
  3. Add friendship
  4. Remove friendship

Remark: Make sure the main functions have a docstring (at least 5 functions!)

Step 1

Think about how to represent the social graph with immutable data structures.

Write code that generate a graph with around 1000 members and 5000 friend relationships.

For sake of simplicity, you can represent a member with a string that contains the member name (and assume that no two members have the same name).

Remark: The name of the persons should be real names like David or Jessica. Not machine generated names like "xhcjhfjd".

Step 2

Write functions that add or remove members and friends. The functions should return a new version of the graph.

Step 3

Write functions that query the graph:

  1. Are two members friends?
  2. What's the average number of friends of a member
  3. Are two members connected?

Good luck!

Feel free to ask questions on Slack for clarification or πŸ†˜ help.