Graphs Flashcards

Learn

1
Q

How do you represent a graph with an adjacency list?

A

Use a mapping where each node points to a list of its neighbors.

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

What’s an adjacency matrix?

A

A 2D grid where each cell shows whether an edge exists between nodes.

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

What’s the difference between a directed and undirected graph?

A

Directed graphs have one-way edges; undirected graphs have two-way edges.

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

How do you create a graph using a library like NetworkX?

A

Use functions to add nodes and edges to a graph object.

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

When should you use an adjacency list instead of a matrix?

A

For sparse graphs where memory efficiency is important.

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

What’s the complexity of adding/removing edges in lists vs matrices?

A

Both are O(1), but adjacency lists use less memory in sparse graphs.

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

What are the pros and cons of adjacency lists and matrices?

A

Lists save space and are good for sparse graphs; matrices allow fast lookups but use more space.

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

What does an adjacency list with node A pointing to B and C mean?

A

Node A is connected to nodes B and C.

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

How do you represent a weighted directed graph?

A

Use nested mappings where each edge has an associated weight.

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