Knowledge graphs
How connected are you?
π School maths Β· Years 8β9Networks & problem solving β Count steps along connections to find the shortest path.Maths by year β
The Case. They say everyone is only a few friends away from anyone on Earth. A knowledge graph β dots for people, lines for friendships β lets a computer prove it.
Your tools. Plain Python explores the graph friend-by-friend to find the shortest chain; matplotlib draws it.
Investigate. Press Run. The orange path is the shortest chain of friends from You to Star.
- This ‘spread out and search’ idea is how maps find routes and how search engines connect facts.
- Add a new friendship to the list and watch the shortest path change.
your_code.py
Starting Pythonβ¦
The Reveal
Starting Pythonβ¦ (first time only β a few seconds)
ποΈ Detective's notes
Bundles your findings, chart and code into one PDF you can keep, print or hand in.
π§© How this code works
The tools it uses
- Matplotlib β your crayon box β it turns numbers into charts and pictures.
- NumPy β a row of boxes that holds numbers, so you can do maths to all of them at once.
- collections β handy containers, like a queue for exploring step by step.
What this one does
- β’ It draws a line chart β great for change over time.
- β’ It draws a scatter graph β great for one thing vs another.
How to read it, top to bottom
- 1. Import β bring in the tools (listed above).
- 2. The data β the lists and numbers near the top. These are the bits you change.
- 3. The work β a little maths, or a loop that repeats a step.
- 4. Show it β
print(...)writes words;plt.show()draws the picture.
Use it for your own problems
- Change the numbers at the top and press Run β nothing breaks, so experiment!
- Ask your own version of the question β swap in your family, your scores, your week.
- The same tools work on any numbers β that's the superpower you're learning.
Need a hint?
The computer checks all friends 1 hop away, then 2 hops, then 3 β the first time it reaches Star is the shortest path.