Graph Algorithms Flashcards

Week 2.12 (30 cards)

1
Q

5 typical operations of graphs as ADT

A
  1. determine whether there is an edge between 2 given vertices
  2. identify all edges
  3. find all vertices adjacent to a given vertex
  4. insert/delete a vertex
  5. insert/delete an edge by 2 vertices of the graph
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

3 data structures graphs can be based on

A
  1. adjacency lists
  2. adjacency matrix
  3. incidence matrix
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

describe adjacency matrix implementation

A
  • for every vertex, there is a singly linked list of its neighbours
  • lists are accessed using an array of vertices
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how are the matrixes implemented

A

2-d arrays

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

space efficiency of adjacency lists

A

theta(n + m)

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

space efficiency of adjacency matrix

A

theta(n^2)

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

space efficiency of incidence lists

A

theta(nm)

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

big theta of determining whether there is an edge between 2 given vertices for adjacency lists

A

deg(v)

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

big theta of determining whether there is an edge between 2 given vertices for adjacency matrix

A

1

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

big theta of determining whether there is an edge between 2 given vertices for incidence matrix

A

m

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

big theta to identify all edges in an adjacency list

A

n + m

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

big theta to identify all edges in an adjacency matrix

A

n^2

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

big theta to identify all edges in an incidence matrix

A

nm

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

big theta to find all vertices adjacent to a given vertex in an adjacency list

A

deg(v)

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

big theta to find all vertices adjacent to a given vertex in an adjacency matrix

A

n

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

big theta to find all vertices adjacent to a given vertex in an incidence list

17
Q

2 types of graph traversal algorithms

A
  1. depth-first search (DFS)
  2. breadth-first search (BFS)
18
Q

describe DFS

A
  • algorthim selects a start vertex and marks it as visited
  • goes as far down one path until it reaches the leaf node before starting to explore alternative paths
  • visited nodes stored in a stack
19
Q

outputs of DFS

A
  1. vertices printed in order of visit
  2. depth-first numbering
  3. DFS forest
20
Q

big theta of depth-first search

21
Q

big theta of DFS on an adjacency matrix

22
Q

describe BFS

A
  • visits all neighbours of the start vertex and only after explores the vertices further away
  • visited vertices kept in a queue
23
Q

big theta of BFS

24
Q

big theta of BFS as an adjacency matrix

25
outputs of BFS
1. vertices printed in order of visit 2. BFS numbering 3. BFS forest
26
applications of DFS & BFS
1. checking connectivity and identifying connected components 2. checking for a cycle 3. finding a path with the fewest numbner of edges between 2 given nodes - BFS preferred 4. finding articulation points of a graph
27
describe topological sorting
process of assigning a linear ordering to the vertices of a directed acyclic graph so that if there is an arc from vertex v to w, then v appears before w in linear ordering
28
how to achieve topological sorting
DFS
29
pseudocode DFS
30
pseudocode BFS