Graphs - Chapter 9 Flashcards
A blank is a data structure for representing connections among items, and consists of vertices connected by edges
graph
A blank (or node) represents an item in a graph.
vertex
An blank represents a connection between two vertices in a graph.
edge
For a given graph, the number of vertices is commonly represented as blank, and the number of edges as blank
V
E
Two vertices are blank if connected by an edge.
adjacent
A blank is a sequence of edges leading from a source (starting) vertex to a destination (ending) vertex.
path
The blank is the number of edges in the path.
path length
The blank between two vertices is the number of edges on the shortest path between those vertices
distance
Blank are often used to represent a geographic map, which can contain information about places and travel routes. Ex: Vertices in a graph can represent airports, with edges representing available flights. Edge weights in such graphs often represent the length of a travel route, either in total distance or expected time taken to navigate the route. Ex: A map service with access to real-time traffic information can assign travel times to road segments.
Graphs
A graph can be used to represent relationships between products. Blank in the graph corresponding to a customer’s purchased products have adjacent vertices representing products that can be recommended to the customer.
Vertices
A graph may use a vertex to represent a person. An blank in such a graph represents a relationship between 2 people. In a graph representing a social network, an edge commonly represents friendship. In a graph representing a professional network, an edge commonly represents business conducted between 2 people.
edge
Various approaches exist for representing a graph data structure. A common approach is an blank.
adjacency list
two vertices are adjacent if connected by an edge. In an blank graph representation, each vertex has a list of adjacent vertices, each list item representing an edge.
adjacency list
A key advantage of an adjacency list graph representation is a size of blank, because each vertex appears once, and each edge appears twice. V refers to the number of vertices, E the number of edges.
O(V + E)
A key disadvantage of an adjacency list graph is that determining whether two vertices are adjacent is blank, because one vertex’s adjacency list must be traversed looking for the other vertex, and that list could have V items.
O(V)
in most applications, a vertex is only adjacent to a small fraction of the other vertices, yielding a blank. A balnk has far fewer edges than the maximum possible.
sparse graph
In an blank 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.
adjacency matrix
Assuming the common implementation as a two-dimensional array whose elements are accessible in blank, then an adjacency matrix’s key benefit is O(1) determination of whether two vertices are adjacent: The corresponding element is just checked for 0 or 1.
O(1)
A key drawback is blank size. Ex: A graph with 1000 vertices would require a 1000 x 1000 matrix, meaning 1,000,000 elements. An adjacency matrix’s large size is inefficient for a sparse graph, in which most elements would be 0’s.
O(V^2)
An adjacency matrix only represents blank among vertices; if each vertex has data, like a person’s name and address, then a separate list of vertices is needed.
edges
An algorithm commonly must visit every vertex in a graph in some order, known as a blank.
graph traversal
A blank is a traversal that visits a starting vertex, then all vertices of distance 1 from that vertex, then of distance 2, and so on, without revisiting a vertex.
breadth-first search (BFS)
An algorithm for blank enqueues the starting vertex in a queue. While the queue is not empty, the algorithm dequeues a vertex from the queue, visits the dequeued vertex, enqueues that vertex’s adjacent vertices (if not already discovered), and repeats.
breadth-first search
When the BFS algorithm first encounters a vertex, that vertex is said to have been blank.
discovered