Graph Data Structures in Java
- 59Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
59 questions
- 1A graph is a nonlinear data structure made up of vertices and_____.
Hint
These are the connections between nodes.
Answer
edges
Explanation
Graphs consist of vertices, which hold data, and edges, which connect vertices.
- 2Another common name for a vertex in a graph is a_____.
Hint
It is the point or entity represented in the graph.
Answer
node
Explanation
A vertex is a single node in a graph and can hold data.
- 3A graph is an ideal data structure for modeling_____.
Hint
Examples include transportation systems and social connections.
Answer
networks
Explanation
Graphs model networks by representing entities as vertices and their connections as edges.
- 4In a neighborhood transportation graph, bus stops can be represented as_____, while bus routes between stops are edges.
Hint
These represent the individual locations in the network.
Answer
vertices
Explanation
Each bus stop is a vertex, and a route connecting stops is an edge.
- 5In a graph representing the web, web pages are vertices and the links connecting them are_____.
Hint
They connect one web page to another.
Answer
hyperlinks
Explanation
The example models pages as vertices and hyperlinks between them as edges.
- 6In a social network graph, people are vertices and their relationships can be represented by_____.
Hint
These are the connections between people in the example.
Answer
friendships
Explanation
The social network example represents each person as a vertex and each friendship as an edge.
- 7A sequence of vertices connected by edges, possibly through intermediate vertices, forms a_____.
Hint
It describes a way to travel through a graph from one vertex to another.
Answer
path
Explanation
A path connects vertices through edges and may include intermediate vertices.
- 8A graph is disconnected when no_____exists between some pair of vertices.
Hint
Without this, one vertex cannot be reached from the other.
Answer
path
Explanation
A disconnected graph has at least two vertices for which no connecting route through edges exists.
- 9An undirected edge represents a connection that works in_____directions.
Hint
The connection can be followed either way.
Answer
both
Explanation
In an undirected graph, the connection is bidirectional rather than having a single arrow direction.
- 10In a weighted graph, a number associated with an edge can represent the cost or_____of using that connection.
Hint
For example, it can indicate how far apart two bus stops are.
Answer
distance
Explanation
Edge weights can represent quantities such as distance or expense associated with traveling along an edge.
- 11A vertex in the described Java design stores its data and a list of connections represented by_____instances.
Hint
Each instance describes a connection to another vertex.
Answer
edge
Explanation
The vertex maintains a list of edge instances to represent its connections to other vertices.
- 12The Java vertex class stores its connections in an_____of edge objects.
Hint
It is a resizable list collection in Java.
Answer
ArrayList
Explanation
The vertex class uses an ArrayList to hold its edge instances.
- 13The vertex constructor assigns the supplied input data to the vertex's_____variable.
Hint
This variable holds the value associated with the vertex.
Answer
data
Explanation
The constructor initializes the vertex's data field from the input parameter.
- 14When a vertex is constructed, its edge list is initialized as a new_____.
Hint
The collection will hold the vertex's edge instances.
Answer
ArrayList
Explanation
The constructor creates a new ArrayList of edges so the vertex can maintain its connections.
- 15An edge object in the described design records a start vertex, an end vertex, and optionally a_____.
Hint
This value can represent the cost of traveling along the edge.
Answer
weight
Explanation
The edge stores its endpoints and a weight representing a value such as distance or expense.
- 16The edge class uses Java's_____type for a weight that may be absent and represented by null.
Hint
It is the object wrapper for the primitive integer type.
Answer
Integer
Explanation
An Integer can hold null, whereas the primitive int cannot.
- 17The graph class stores all of its vertices in a list of_____instances.
Hint
This is the class representing each node in the graph.
Answer
vertex
Explanation
The graph maintains a collection of vertex instances representing its nodes.
- 18The graph's directed and weighted Boolean properties describe whether edges have direction and whether they have_____.
Hint
These are numerical values associated with edges.
Answer
weights
Explanation
The graph tracks whether it is directed and whether its edges carry weights.
- 19The graph's add vertex method creates a vertex, stores it in the graph, and_____the new vertex.
Hint
The caller can save and use the newly created object.
Answer
returns
Explanation
The method adds the new vertex to the graph's vertex list and returns that vertex.
- 20A graph-level add edge method can hide lower-level details from its caller through a layer of_____.
Hint
This lets a user use functionality without needing to know its internal implementation.
Answer
abstraction
Explanation
The graph provides an interface for adding edges, so callers need not directly manage the vertex and edge implementation.
- 21For an undirected graph, adding an edge between two vertices must create connections in_____directions.
Hint
Each endpoint must be able to reach the other.
Answer
both
Explanation
The graph-level add edge operation adds the reverse connection as well when the graph is undirected.
- 22For a directed graph, the graph-level add edge operation adds a connection from the start vertex to the_____vertex.
Hint
This is the destination endpoint of the directed edge.
Answer
end
Explanation
A directed edge points from its start vertex toward its end vertex, without automatically adding a reverse edge.
- 23When adding an edge to an unweighted graph, the implementation can set its weight to_____.
Hint
The value indicates that no weight was supplied.
Answer
null
Explanation
The described graph method checks whether the graph is weighted and uses null when it is not.
- 24The vertex remove edge method uses a predicate to remove edges whose_____vertex matches the requested vertex.
Hint
This endpoint is the destination stored in the edge.
Answer
end
Explanation
The method filters the edge list by checking whether each edge's end vertex equals the supplied vertex.
- 25A vertex's get data helper method returns the value stored in that vertex's_____field.
Hint
The constructor initializes this field from its input.
Answer
data
Explanation
The get data method exposes the vertex's stored data value.
- 26A graph's get vertices method returns the list containing the graph's_____.
Hint
These are all the nodes stored in the graph.
Answer
vertices
Explanation
The method returns the graph's ArrayList of vertex instances.
- 27A graph's get vertex by value method searches vertex data and returns the matching vertex, or_____if no match exists.
Hint
This value can signal that the requested stop or vertex was not found.
Answer
null
Explanation
The method compares each vertex's data with the requested value and returns null if none matches.
- 28A visited list or set prevents a graph search from visiting the same vertex_____.
Hint
This is especially useful when the graph contains cycles.
Answer
multiple times
Explanation
Tracking visited vertices prevents repeated processing and helps avoid infinite loops in cyclical graphs.
- 29Depth-first search explores one path as far as it can before backing up, whereas breadth-first search explores in_____.
Hint
It visits the start vertex's neighbors before moving to the next level.
Answer
layers
Explanation
BFS expands outward from the starting point one layer of neighboring vertices at a time.
- 30A breadth-first search begins by examining the starting vertex and its direct_____.
Hint
These vertices are connected to the start by one edge.
Answer
neighbors
Explanation
The first layer in BFS consists of the start vertex's direct neighbors.
- 31In the described implementations, depth-first and breadth-first search each have an upper-bound runtime of_____.
Hint
The search examines vertices and edges; use V for vertices and E for edges.
Answer
O(V+E)
Explanation
In the upper-bound case, both algorithms examine every vertex and edge, giving runtime O(V+E).
- 32Besides finding paths, depth-first search can organize vertex values in a clear order of_____.
Hint
It describes the sequence in which vertices are encountered.
Answer
visitation
Explanation
DFS can produce an ordered list of vertices or their values based on when they are visited.
- 33The three DFS traversal orders discussed are preorder, postorder, and reverse_____.
Hint
The last of these is also called topological sort in the lesson.
Answer
postorder
Explanation
The lesson describes preorder, postorder, and reverse postorder as three DFS traversal orders.
- 34In the described preorder traversal, a vertex is added to the output list before it is added to the_____.
Hint
This structure keeps track of the search's pending vertices.
Answer
stack
Explanation
Preorder records the vertex in the visited and output lists before adding it to the stack.
- 35In the described postorder traversal, a vertex is added to the output list after it is popped off the_____.
Hint
It is the data structure from which the vertex is removed.
Answer
stack
Explanation
Postorder records a vertex in the output list after that vertex has been popped from the stack.
- 36Reverse postorder produces an output list that is exactly the_____of the postorder list.
Hint
The order of the postorder entries is flipped.
Answer
reverse
Explanation
Reverse postorder is formed by reversing the postorder output list.
- 37Reverse postorder is also referred to in the lesson as_____sort.
Hint
This ordering is associated with directed graph structure.
Answer
topological
Explanation
The lesson identifies reverse postorder as topological sort.
- 38When DFS has several available neighbors in the numerical example, it chooses the_____numbered option first.
Hint
For example, it selects 3 before 4.
Answer
smallest
Explanation
The walkthrough assumes the algorithm prefers the smallest numerical neighbor whenever there is a choice.
- 39In the example DFS starting at 1, the preorder visitation sequence is_____.
Hint
The search takes the smaller available neighbor and records vertices before finishing their branches.
Answer
1, 3, 2, 5, 4
Explanation
Following the example's neighbor choices, preorder visits 1, then 3, 2, 5, and finally 4.
- 40In the same example, the postorder sequence is_____.
Hint
A vertex is recorded after its explored descendants have been completed.
Answer
5, 2, 4, 3, 1
Explanation
The walkthrough's postorder output is 5, 2, 4, 3, 1.
- 41In the same example, reverse postorder is_____.
Hint
Reverse the order of the postorder sequence.
Answer
1, 3, 4, 2, 5
Explanation
Reversing 5, 2, 4, 3, 1 produces 1, 3, 4, 2, 5.
- 42The recursive DFS implementation explores a neighbor only if that vertex is not already in the_____list.
Hint
This collection tracks which vertices have already been encountered.
Answer
visited
Explanation
The implementation checks the visited vertices list before adding a neighbor and making the recursive call.
- 43After marking a new neighbor visited, recursive DFS calls itself with that_____as the next starting point.
Hint
It is the vertex reached by following the current edge.
Answer
neighbor
Explanation
The recursive call continues the depth-first exploration from the newly discovered neighboring vertex.
- 44Breadth-first search processes the start vertex, then its direct neighbors, then the neighbors of those vertices, proceeding layer by_____.
Hint
This pattern expands outward evenly from the origin.
Answer
layer
Explanation
BFS explores all vertices at one distance layer before proceeding to the next layer.
- 45Unlike the recursive DFS implementation, the described BFS implementation uses a_____to manage vertices waiting to be explored.
Hint
This data structure processes items in the order they are added.
Answer
queue
Explanation
The BFS implementation enqueues the start and neighboring vertices, then removes them as it explores the graph.
- 46BFS checks all of the current vertex's direct neighbors rather than following only its first_____.
Hint
Each one connects the current vertex to a neighboring vertex.
Answer
edge
Explanation
BFS iterates across every edge of the current vertex so that all of its direct neighbors can be considered.
- 47In BFS, a newly discovered neighbor is added to both the visited list and the_____.
Hint
The neighbor will be processed after earlier queued vertices.
Answer
queue
Explanation
The implementation marks each unseen neighbor visited and enqueues it for later exploration.
- 48For the example starting at 1, breadth-first traversal produces the order_____.
Hint
Visit the start's direct neighbors before exploring the next layer.
Answer
1, 3, 4, 2, 5
Explanation
The walkthrough's BFS order is 1, 3, 4, 2, 5, because it explores outward by layers.
- 49Dijkstra's algorithm is used to find the shortest_____between vertices in a weighted graph.
Hint
It measures the minimum total cost of traveling along edges.
Answer
distance
Explanation
The algorithm computes shortest distances from a starting vertex to other vertices using edge weights.
- 50Dijkstra's algorithm initializes the distance from the starting vertex to itself as_____.
Hint
No edges need to be traveled to remain at the starting point.
Answer
zero
Explanation
The source vertex has distance zero from itself; other vertices initially have an unknown, effectively infinite distance.
- 51At each iteration, Dijkstra's algorithm removes the unvisited vertex with the_____known distance.
Hint
It selects the smallest tentative distance first.
Answer
minimum
Explanation
The algorithm repeatedly processes the unvisited vertex whose current distance estimate is smallest.
- 52When processing an edge, Dijkstra's algorithm calculates a candidate distance by adding the current distance to the edge's_____.
Hint
This value represents the cost of traversing that edge.
Answer
weight
Explanation
The alternative distance to a neighbor is the distance to the current vertex plus the edge weight.
- 53Dijkstra's algorithm updates a neighbor's distance only when the candidate distance is_____than its existing distance.
Hint
The new route must improve on the route already recorded.
Answer
less
Explanation
If the alternative route is shorter, the algorithm replaces the neighbor's current distance with the candidate value.
- 54A priority queue supports Dijkstra's algorithm by allowing it to retrieve the entry with the_____priority.
Hint
This entry represents the next closest unvisited vertex.
Answer
smallest
Explanation
The priority queue orders entries by priority so the minimum-distance vertex can be removed efficiently.
- 55In the described Dijkstra implementation, one dictionary maps vertex values to distances, while another records each vertex's_____vertex.
Hint
Following these references can reconstruct a route.
Answer
previous
Explanation
The distance dictionary stores shortest-distance estimates, and the previous dictionary tracks the vertex preceding each vertex on a shortest route.
- 56The previous-vertex dictionary is used to reconstruct the shortest_____after distances have been computed.
Hint
It is the sequence of vertices to follow from start to destination.
Answer
path
Explanation
Following the stored previous-vertex references backward from the target allows the implementation to build the path.
- 57The example's shortest route from A to E is A to C to E, with a total distance of_____.
Hint
Add the edge weights 2 and 1.
Answer
3
Explanation
The route through C has total weight 2+1=3, which is less than the alternative routes described.
- 58In the example, the shortest distance from A to D is_____.
Hint
The best route described goes from A to B and then B to D.
Answer
6
Explanation
The route A to B to D has weights 4 and 2, giving a total distance of 4+2=6.
- 59With a priority queue, the described Dijkstra implementation has runtime_____.
Hint
The lesson expresses the bound using the number of edges and the number of vertices multiplied by a logarithmic factor.
Answer
O(E+VlogV)
Explanation
The stated runtime is O(E+VlogV), where E is the number of edges and V is the number of vertices.

Ask anything
We've read this whole study set, so questions about it get the best answers.