Ch 9: Graphs I Flashcards
what is a graph?
a data structure for representing connections among items, and consists of vertices connected by edges
what is a vertex(node)?
represents an item in a graph
what is an edge?
represents a connection between two vertices in a graph
what does it mean for two vertices to be adjacent?
they are connected by a single edge
what is a path?
a sequence of edges leading from a source(starting) vertex to a destination(ending) vertex
what is path length?
the number of edges in the path
what is distance?
the number of edges on the path between two vertices
what does the shortest path algorithm do?
minimizes the sum of edges to the destination, not shortest time
what is an adjacency list?
- graph representation
- each vertex has a list of adjacent vertices, each list item represents an edge
what is the advantage of an adjacency list?
has a size of O(V+E) (v- vertices, e- edges) because each vertex appears once and each edge appears twice
what is the disadvantage of an adjacency list?
determining whether the two vertices are adjacent is O(V) because one vertex’s adjacent list must be traversed looking for the other vertex
what is a sparse graph?
when each vertex has far fewer edges than the maximum possible
in most applications, when a vertex is only adjacent to a fraction of the other vertices, what does it result in?
a sparse graph
what is an adjacency matrix?
- 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
in an adjacency matrix that is implemented as a 2-d array, what is the run time of accessing elements?
O(1)