Ch 9: Graphs I Flashcards

1
Q

what is a graph?

A

a data structure for representing connections among items, and consists of vertices connected by edges

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

what is a vertex(node)?

A

represents an item in a graph

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

what is an edge?

A

represents a connection between two vertices in a graph

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

what does it mean for two vertices to be adjacent?

A

they are connected by a single edge

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

what is a path?

A

a sequence of edges leading from a source(starting) vertex to a destination(ending) vertex

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

what is path length?

A

the number of edges in the path

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

what is distance?

A

the number of edges on the path between two vertices

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

what does the shortest path algorithm do?

A

minimizes the sum of edges to the destination, not shortest time

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

what is an adjacency list?

A
  • graph representation

- each vertex has a list of adjacent vertices, each list item represents an edge

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

what is the advantage of an adjacency list?

A

has a size of O(V+E) (v- vertices, e- edges) because each vertex appears once and each edge appears twice

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

what is the disadvantage of an adjacency list?

A

determining whether the two vertices are adjacent is O(V) because one vertex’s adjacent list must be traversed looking for the other vertex

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

what is a sparse graph?

A

when each vertex has far fewer edges than the maximum possible

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

in most applications, when a vertex is only adjacent to a fraction of the other vertices, what does it result in?

A

a sparse graph

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

what is an adjacency matrix?

A
  • graph representation
  • each vertex is assigned to a matrix row and column, and a matrix element is 1 if the corresponding two vertices have an edge or is 0 otherwise
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

in an adjacency matrix that is implemented as a 2-d array, what is the run time of accessing elements?

A

O(1)

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

in an adjacency matrix that is implemented as a 2-d array, what is the run time of determining whether two vertices are adjacent or not?

A

O(1)

17
Q

what is the key drawback of an adjacency matrix?

A

size is O(V^2)

18
Q

what is graph traversal?

A

an algorithm that commonly visits every vertex in a graph in some order

19
Q

what is breadth-first search (BFS)?

A

a traversal that visits the starting index then all vertices of distance 1 from the vertex, then distance 2, then so on without revisiting a vertex

20
Q

Is BFS unique? Why?

A

no because there can be multiple pathways

21
Q

explain the BFS traversal algorithm

A
  • enqueues starting vertex into a queue
  • while the queue is not empty, dequeue the vertex
  • check that dequeued vertex
  • enqueue its adjacent vertices that have yet to be discovered
    repeat
22
Q

what does it mean for a vertex to be discovered?

A

algorithm visited the vector

23
Q

what is a frontier?

A

vertices in the queue, being vertices thus far discovered but not yet visited

24
Q

what is depth-first search (DFS)?

A

a traversal that visits a starting vertex then visits every vertex along each path starting from that vertex to the path’s end before backtracking

25
Q

explain the DFS traversal algorithm

A
  • push starting vertex to stack
  • while the stack is not empty, pop the vertex from the top
  • if vertex has not been visited visit vertex and push adjacent vertices
    repeat