Docsity

Graph Implementations: True/False and Multiple Choice Questions, Study notes of Computer Science

Toggle sidebar
bg1
Chapter 29 - Graph Implementations
True/False (10)
1. An undirected graph is symmetric.
2. In a graph represented by an adjacency matrix, you cannot use boolean values for an
unweighted graph.
3. An adjacency matrix occupies a fixed amount of space dependent on the number of edges in the
graph.
4. In an adjacency list, space is not reserved for edges that do not exist.
5. An adjacency matrix uses less memory than an adjacency list.
6. For a dense graph, using an adjacency matrix to represent the graph is a better choice.
7. Regardless of how you implement a graph, you need a container such as a dictionary for the
graph’s vertices.
8. Using an adjacency list, you need to search the entire list to determine if an edge exists between
any two given vertices.
9. An adjacency matrix uses less space for a sparse graph than an adjacency list.
10. Using an adjacency matrix, you can use an edge weight of infinity to represent that there is no
edge between any two given vertices.
Short Answer (5)
1. Fill in the adjacency matrix for the following graph.
X
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
pf3
pf4
pf5

Partial preview of the text

Download Graph Implementations: True/False and Multiple Choice Questions and more Study notes Computer Science in PDF only on Docsity!

Chapter 29 - Graph Implementations True/False (10)

  1. An undirected graph is symmetric.
  2. In a graph represented by an adjacency matrix, you cannot use boolean values for an unweighted graph.
  3. An adjacency matrix occupies a fixed amount of space dependent on the number of edges in the graph.
  4. In an adjacency list, space is not reserved for edges that do not exist.
  5. An adjacency matrix uses less memory than an adjacency list.
  6. For a dense graph, using an adjacency matrix to represent the graph is a better choice.
  7. Regardless of how you implement a graph, you need a container such as a dictionary for the graph’s vertices.
  8. Using an adjacency list, you need to search the entire list to determine if an edge exists between any two given vertices.
  9. An adjacency matrix uses less space for a sparse graph than an adjacency list.
  10. Using an adjacency matrix, you can use an edge weight of infinity to represent that there is no edge between any two given vertices. Short Answer ( 5 )
    1. Fill in the adjacency matrix for the following graph. X 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

6 7 8 9

  1. Fill in the adjacency matrix for the following graph. X 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  2. Explain the steps to add an edge to the ADT DirectedGraph.
  3. In the ADT DirectedGraph, what is the purpose of the data fields visited , previousVertex and cost?
  4. Explain why we use an inner class Edge even if there is no weight associated with edges. Multiple Choice (19)
  5. A common implementation of a graph that uses a two dimensional array to represent the graph’s edges is called a(n) a. adjacency matrix b. graph array c. adjacency array d. adjacency list

c. a variable amount of space dependent on the number of vertices in the graph d. a variable amount of space dependent on the number of edges in the graph

  1. For a sparse graph, an adjacency lists uses _____ memory than an adjacency matrix. a. less b. more c. the same amount of d. none of the above
  2. Each vertex in a graph of n vertices can be the origin of at most _____ edges. a. n – 1 b. n + 1 c. n d. 1
  3. In the interface VertexInterface, the connect methods a. connect two vertices b. connect two edges c. connect two graphs d. none of the above
  4. In the interface VertexInterface, the connect methods require _____ operations. a. O(n) b. O(1) c. O(log n) d. O(n^2 )
  5. In the ADT graph, the method addVertex has efficiency a. O(n) b. O(log n) c. O(n^2 ) d. O(1)
  6. In the ADT graph, the method addEdge has efficiency a. O(n) b. O(log n) c. O(n^2 ) d. O(1)
  7. In the ADT graph, the method hasEdge has efficiency a. O(n) b. O(log n)

c. O(n^2 ) d. O(1)

  1. In the ADT graph, the method isEmpty has efficiency a. O(1) b. O(log n) c. O(n^2 ) d. O(n)
  2. In the ADT graph, the method getNumberOfVertices has efficiency a. O(1) b. O(log n) c. O(n^2 ) d. O(n)
  3. In the ADT graph, the method getNumberOfEdges has efficiency a. O(1) b. O(log n) c. O(n^2 ) d. O(n)
  4. In the ADT graph, the method clear has efficiency a. O(1) b. O(log n) c. O(n^2 ) d. O(n)