Graphs Flashcards

1
Q

Basics 1

A
  • A collection of nodes that may or may not be connected between them
  • Nodes are vertices and may be represented as integers, and relations between vertices are edges
  • Cycles:
    * Occur in a graph when three or more vertices are connected to form a closed-loop
    * On interview questions must clarify what exactly constitutes a cycle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Basics 2

A
  • A graph can be represented by a list or hash table that contains two things: the list of nodes, and the list of the edges of every vertice
  • Traversing a graph has two ways:
    * Depth-First Search: start traversing deep first by starting on one node and then going deep into that node
    * Breadth-First Search: start traversing wider first by starting on one node and then for all the edges of that node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Types 1

A
  • Connected graph:
    * When for every pair of vertices there’s a path of one or more edges that connect them. For example the graph of rooms of a house
  • Types:
    * Strongly connected: if there are bidirectional connections between every pair of vertices
    * Weakly connected: if there are connections, not necessarily bidirectional, between every pair of vertices
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Types 2

A
  • Directed graph: when the edges can only be traversed in one specific direction. For example a graph of airports and flights
  • Undirected graph: when the edges can be traversed in every direction. For example a graph of friends
  • Cyclic graph: when a graph has at least one cycle
  • Acyclic graph: when a graph has no cycles
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Space-time complexities

A
  • Initializing a graph is a linear operation. It’s O(V+E) S, where V is the number of vertices and E is the total number of edges for every node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly