Block 3: Graph Algorithms Flashcards
how would you write th edge connecting vertices u and v?
uv
What does “u and v are adjacent” mean?
that u and v are neighbours on the graph
what does it mean for a graph to be eulerian?
every edge can be visited in a single tour.
what is hamiltonicity?
whether on not you can visit every vertex of a graph in a single tour
what are 2 popular ways to stare edges?
adjacency lists and adjacency matrix
what is the time complexity for finding whether or not an edge exists?
Θ(1) for the first, Θ(dG(v)) for the second
what is the time to iterate through all edges of a graph?
Θ(n^2) for the first, Θ(n + m) for the second
What is the sum of degrees theorem?
the sum of degrees of vertices in a graph G = (V, E) equals twice the number of edges in G.
what is a graph traversal?
an algorithm for visiting every vertex of a graph
what are the 2 main orders of graph traversal?
DFS and BFS
what is the DFS process?
- mark vertex v
- visit v
- for every neighbour u of v, if u unmarked, call DFS on u recursively
What is the BFS process?
- before calling, initialise with all vertices unmarked
- create an empty queue
- mark a vertex v, add v to queue
- until queue is empty
i. dequeue a vertex u from the queue
ii. for every neighbour w of u, if w is unmarked, mark w and add to queue
what is memoization?
remember all computed subproblems to avoid recomputation in a big table
what is dynamic programming?
replace “recursive scaffolding” to work directly on the table
What is the knapsack problem definition?
Given n items [I1, I2, .. In], each with a size I.size and a value I.value, and a total capacity c, find the most valuable way to pack items of total size at most c.
what are the common traits between all subproblems in a bigger problem?
> capacity is between 0 and original
> item list is [I1, I2, … , Ii]: first i items
what is the worst case time complexity of a naïve search?
O(nm)
what is the average performance time of Rabin Karp
O(n)
what are the steps for BFS on a graph?
- Before calling, initialise with all vertices unmarked
- create empty queue
- mark a vertex v, add v to queue
- until queue is empty:
i. dequeue a vertex u from the queue
ii. for every neighbour w of u:
> if w is unmarked, mark w and add to queue
what is Pₙ ?
a path on n vertices, a graph with verticies v1, v2, … , vn and edges v1v2, v2v3, … , vn-1vn
what is Cₙ ?
a cycle on n vertices. Obtained if we add edge vnv1 to Pₙ
what is a tree in terms of graphs?
a connected graph with no cycles and n - 1 edges
what is a complete graph on n vertices, Kₙ?
a graph on n vertices in which every 2 vertices are joined by an edge (are adjacent)
what is the DFS pattern on a graph?
- Mark vertex v
- visit v
- for every neighbour u of v; if u in unmarked: call DFS(u) recursively
what makes a graph connected?
a graph is connected if it contains a path from any vertex to any other vertex
what are the maximal connected subgraphs of a disconnected graph?
the connected components of the graph
when do we draw an arc?
whenever the DFS visits a vertex coming from another vertex
what is an arc?
a directed edge
What is the BFS shortest path claim?
A BFS tree with root r always contains the shortest path from r to every vertex
what is a spanning tree?
A tree T = (V, F) with edges from E that connects every vertex of G
what is a minimum spanning tree?
a spanning tree T of minimal total cost
what are the 2 properties of spanning trees?
cycle property and cut property
what is cycle property?
- adding any edge uv to T creates a cycle C
2. removing any edge u’v’ from C creates a new spanning tree