# minte9 LearnRemember

### Graphs

A graphs is a data structure specialized in relationships.
`````` friends = {
'Alice': ['Bob', 'Diana', 'Fred'],
'Bob': ['Alice', 'Cynthia', 'Diana'],
'Cynthia': ['Bob'],
'Diana': ['Alice', 'Bob', 'Fred'],
'Elise': ['Fred'],
'Fred': ['Alice', 'Diana', 'Elise'],
}

print(friends['Alice'])

# ['Bob', 'Diana', 'Fred']
``````

### Directed Graphs

Relationships are not always mutual.
`````` followees = {
'Alice': ['Bob', 'Diana'],
'Bob': ['Cynthia'],
'Cynthia': ['Bob'],
}

assert 'Bob' in followees['Alice']
assert 'Alice' not in followees['Bob']
``````

### Object Oriented

We can implement an undirected graph using an object oriented approach.
`````` class Vertex:
def __init__(self, name):
self.value = name

# if the friendship is mutual (undirected graph),
# we automatically add self vertix

a = Vertex('Alice')
b = Vertex('Bob')
c = Vertex('Cynthia')

print('Alice vertices:', [x.value for x in a.adjacent_vertices])
print('Bob vertices:', [x.value for x in b.adjacent_vertices])

"""
Alice vertices: ['Bob', 'Cynthia']
Bob vertices: ['Alice', 'Cynthia']
"""
``````

### Weighted Graphs

This type of graph adds additional information to the edges of the graph.
`````` class WeightedVertex:
def __init__(self, value):
self.value = value

d = WeightedVertex('Dallas')
t = WeightedVertex('Toronto')