edge / adjacency sets Flashcards

1
Q

graph data structure: edge set

A

stores a set of vertices and a set of edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

graph data structure: adjacency set

A

stores a set of vertices and a dictionary of neighbors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

EdgeSet: add_vertex(self, v):

A

self.V.add(v)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

EdgeSet: add_edge(self, e):

A

self.E.add(e)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

remove_vertex(self,v):

A

self.V.remove(v)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

remove_edge(self, e):

A

self.E.remove(e)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

EdgeSet: __iter__(self):

A

return iter(self.V)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

_neighbors(self, v):

A

nbrs = set(); for e in self.E:
>if e[0] == v: nbrs.add(e[1]);

return nbrs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

class AdjacencySet:

A

initialize with empty set of vertices, empty dict of neighbors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Adjacency set

A

set for vertices, dictionary for edges;
each vertex is a key, value is all neighbors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

AdjacencySet: add_vertex

A

self.V.add(V)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

AdjacencySet: remove_vertex

A

self.V.remove(V)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

AdjacencySet: add_edge(self, e):

A

a, b = e;
if a not in self.nbrs: self.nbrs[a] = {b};

else:
self.nbrs[a].add(b)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

AdjacencySet: remove_edge:

A

a, b = e;
self.nbrs[a].remove(b);

if len(self.nbrs[a]) == 0: self.nbrs.pop(a)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

AdjacencySet: _neighbors:

A

return iter(self.nbrs[v])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly