DS101 – Fundamentals of Data Science
09 Oct 2023
The mental skills and practices related to the following aspects of computing:
1️⃣ Designing computations that get computers to do the jobs for us
2️⃣ Explaining and interpreting the world as a complex information process
We usually have to think like computers to design the proper computations for the job.
We can use computers to create models of the world.
Let us look at a simple, old example of a computational model for urban segregation (McCown 2014) ➡️
Today our focus is on the first aspect:
1️⃣ Designing computations that get computers to do the jobs for us
2️⃣ Explaining and interpreting the world as a complex information process
Recipes for computers
Problem Definition:
Whenever I receive a list of numbers, I want to ensure this list is ordered.
Input:
[10, 20, 42, 29, 50]
Output:
[10, 20, 29, 42, 50]
Computation:
How would you solve it❓
Group up with the people of your respective tables and try to come up with a recipe that solves the problem, regardless of the list size.
Test that your recipe works for the following list:
[237, 153, 311, 33, 854, 212, 368, 42, 892, 755]
After the break:
(no slides, all live demos)
Graph:
🎯 How do we get the shortest path between A and all the other nodes in this graph (i.e between A and B, A and D, A and G, etc…?
Pair with the people in your respective tables and discuss.
Step 1: Mark the source node with a current distance of 0 and the rest with infinity
Step 2: Set the non-visited node with the smallest current distance, as the current node, let’s say c
(initially c
is set to the source node).
Step 3: For each neighbour N
of the current node c
: add the current distance of c
with the weight of the edge c-N
. If it is smaller than the current distance of N
, set it as the new current distance of N
.
Step 4: Mark c
as visited.
Step 5: Go to Step 2 if there are any unvisited nodes.
Source node: A
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | \(\infty\) | \(\infty\) | \(\infty\) | \(\infty\) | \(\infty\) | \(\infty\) |
Unvisited nodes: {A,B,C,D,E,F,G}
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | 2 | 6 | \(\infty\) | \(\infty\) | \(\infty\) | \(\infty\) |
Closest node to source node (based on current distances): B
nodes on path: {A, B}
Unvisited nodes: {A,B,C,D,E,F,G}
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | 2 | 6 | 7 | \(\infty\) | \(\infty\) | \(\infty\) |
Unvisited nodes: {A,B,C,D,E,F,G}
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | 2 | 6 | 7 (via B not C 14) | \(\infty\) | \(\infty\) | \(\infty\) |
Unvisited nodes: {A,B,C,D,E,F,G}
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | 2 | 6 | 7 (via B not C 14) | 17 (A–B–D–E) | 22 (A–B–D–F) | \(\infty\) |
Unvisited nodes: {A,B,C,D,E,F,G}
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | 2 | 6 | 7 (via B not C 14) | 17 (A–B–D–F) | 22 (A–B–D–E) | 19 (A–B–D–F–G) |
For F: distance unchanged since second option (A–B–D–F–E) more costly (23 instead of 22)
Unvisited nodes: {A,B,C,D,E,F,G}
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | 2 | 6 | 7 (via B not C 14) | 17 (A–B–D–E) | 22 (A–B–D–F) | 19 (A–B–D–F–G) |
Possibilities: 22 (A–B–D–F), 23 (A–B–D–E–F), 25 (A–B–D–E–G–F)
Previous distance from (A–B–D–F) unchanged since lowest
No more unvisited nodes
Final shortest distance calculation from A to other nodes
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Distance | 0 | 2 | 6 | 7 | 17 | 22 | 19 |
LSE DS101 2023/24 Autumn Term | archive