Bitpath

Lesson 1 · Unit 01

Nodes and edges

Directed, undirected, and the adjacency list

11 exercisesabout 3 min

What you practise

  • Directed and undirected, degree, building an adjacency list from edges

Try a question from this lesson

Pick one

Four people and their friendships: Ana and Bo, Bo and Cy, Cy and Ana, Cy and Di. Who has the most friends?

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

The adjacency list

A graph is nodes plus edges. The usual way to store one: for every node, keep the list of its neighbours.

A friendship goes both ways (an undirected edge), so it shows up twice: bo is in the list of ana, and ana is in the list of bo.

# friendships: ana-bo, bo-cy
graph = {
    "ana": ["bo"],
    "bo": ["ana", "cy"],
    "cy": ["bo"],
}
print(len(graph["bo"]))   # 2
// friendships: ana-bo, bo-cy
const graph = {
  ana: ["bo"],
  bo: ["ana", "cy"],
  cy: ["bo"],
};
console.log(graph.bo.length); // 2
// friendships: ana-bo, bo-cy
const graph: Record<string, string[]> = {
  ana: ["bo"],
  bo: ["ana", "cy"],
  cy: ["bo"],
};
console.log(graph.bo.length); // 2

TypeScript noteRecord<string, string[]> is an object type: every key is a string and every value is an array of strings.

9 more exercises in the app

  • 2× type the answer
  • 1× true or false
  • 3× multiple choice
  • 1× fill the blanks
  • 1× match the pairs
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy