Graphs Flashcards

1
Q

A _________________ is a pair V, E ,where V is a finite set and E is a binary relation on V.

A

directed graph

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

TRUE or FALSE:
Edges from a vertex to itself (self- loops) are possible in a undirected graph.

A

FALSE. Only possible for directed graphs

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

u -> v

A

u, v is incident from u and is incident to v.

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

u -> v

A

v is adjacent to u.

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

TRUE or FALSE:
In an undirected graph G = V, E , E
consists of unordered pairs of vertices.

A

TRUE

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

u - v

A

u, v is incident on u and v.

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

u - v

A

u is adjacent to v and
v is adjacent to u.

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

In an undirected graph, the ________ of
a vertex is the ________________
incident on it.

A

degree, number of edges

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

In a directed graph:

the ____________of a vertex is the
number of edges leaving it

the _____________ of a vertex is the number
of edges entering it

A

out-degree, in-degree

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

In a directed graph:

the degree of a vertex is the _____ of its in-degree and its out-degree

A

sum

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

A ______ from a vertex v0 to a vertex vk is a sequence of vertices

A

path

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

The _____________ of a path is the number of edges in the path.

A

length

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

A path is _________ if all vertices in the path are distinct.

A

simple

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

Graph Representation using adjacency matrix

A

row is source
column is destination

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

TRUE or FALSE:
In an undirected graph, the adjacency
matrix A is its own transpose: A = AT.

A

TRUE

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

An array Adj of V lists, one for each
vertex in V.

Adj[u] consists of all the vertices adjacent to u in G.

A

Adjacency List

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

Running time of operations:

Check if vertex u is adjacent to vertex v

A

Adj Mat - O(1)
Adj List - O(V)

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

Running time of operations:

List all vertices that
are adjacent to u

A

Adj Mat - O(|V|)
Adj List - O(|V|)

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

Running time of operations:

List all edges of G

A

Adj Mat - O(|V^2|)
Adj List - O(|V| + |E|)

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

Adjacency lists provide a compact way to represent _____________
i.e. E significantly less than V2

A

sparse graphs

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

Adjacency matrices are good for ____________ i.e. E is close to V2.

A

dense graphs

22
Q

Which is better for checking the adjacency between two vertices.

23
Q

________________ visits vertices in waves emanating from the source vertex s.

A

Breadth-first Search (BFS)

24
Q

Starting from source vertex (s), it first visits all neighbors of s

25
BFS uses a ___________ to do this.
queue
26
BFS Algo (Pseudo code)
bfs(int s, int graphsize){ int j, v, visited[MAXGRAPHSIZE]; queue bfs_queue for(j = 0; j
27
_____________ is similar to the tree preorder traversal.
Depth-first search (DFS)
28
The DFS strategy is to _____________ into the graph whenever possible
search deeper
29
DFS explores edges out of the ______________________ that still has unexplored edges leaving it.
most recently visited vertex v
30
In DFS, once all v's edges are explored, the search "___________" to the previous vertex and its unexplored edges.
backtracks
31
DFS uses a _________
stack
32
DFS Algo (Pseudo code)
dfs(int s, int graphsize){ int j, v, visited[MAXGRAPHSIZE] stack dfs_stack for(j=0;j
33
Running time DFS and BFS
O(V+E)
34
A ______________ is a subset of the edges that connects all the vertices together without forming a cycle.
spanning tree
35
Problem Domain: Find a spanning tree whose sum of all the edge-weights is the minimum
Minimum Spanning Tree Problem
36
Algorithms for Minimum Spanning Tree Problem
Kruskal's and Prim's Algorithm
37
Grows a forest of edges by considering each edge in sorted order by weight If the edge joins two distinct trees in the forest, it is added to the forest merging the two trees.
Kruskal's Algorithm
38
connect trees via the shortest edge
Kruskal's Algorithm
39
Kruskal's Algorithm Pseudo code
1. Sort the edges in increasing order of weight 2. Starting from the edge with the least weight to the last (or until the vertices are included in the tree): - add the to the MST if it doesn't form a cycle
40
How to check if the addition of an edge(u,v) will form a cycle in the MST
If both u and v belong the the same tree, the edge(u,v) cannot be added to the forest without creating a cycle
41
The tree starts from an arbitrary root vertex and grows until it spans all the vertices in V Each step adds to the tree an edge that connects it to an isolated vertex, without forming a cycle
Prim's Algorithm
42
maintain a tree by adding the nearest neighbor
Prim's Algorithm
43
Prim's Algo Pseudo code
prims(source): initialize visited array to zeroes initialize distance array d to 999 initialize parent array p to -1 d[source] = 0 for number of vertices: find vertex u, !visited[u] and d[u] is minimum visited[u] = TRUE for each vertex v adjacent to u and !visited[v] distance = weight(edge(u,v)) if distance < d[v]: d[v] = distance p[v] = u
44
To get the MST in Prim's Method, get the edges (parent, vertext)
To get the total edge weight of the MST, take the summation of the distance array
45
A shortest path from vertex u to vertex v is any path p that has the minimum weight (or shortest path length if unweighted)
Single-Source Shortest Path Problem (SSSP)
46
Given a graph G = (V,E) find a shortest path from a given source vertex s ∈ V to every vertex v ∈ V.
SSSP
47
Dijkstra's Algorithm Pseudo code
dijkstra(source): initialize visited array to zeroes initialize distance array d to 999 initialize parent array p to -1 d[source] = 0 for number of vertices: find vertex u, !visited[u] and d[u] is minimum visited[u] = TRUE for each vertex v adjacent to u and !visited[v] distance = d[u] + weight(edge(u,v)) if distance < d[v]: d[v] = distance p[v] = u
48
Lemma: A shortest path between two vertices ___________________________ within it.
contains other shortest paths
49
To get the shortest path, trace ______________ from the destination vertex to the source vertex (using parent Array)
BACKWARDS
50