Computer Science Test 8 Nddc Scholarship
Computer Science Test 8 Nddc Scholarship
Question 91
Which of the following statements regarding Kruskal's and Prim's algorithms is correct?
The efficiency of MST algorithms often depends on the density of the graph. Kruskal’s algorithm has a time complexity of \(O(E \log E)\) or \(O(E \log V)\), which is dominated by the time taken to sort the edges.
In a 'sparse' graph (where the number of edges \(E\) is relatively small and close to \(V\)), Kruskal’s tends to perform better and is often simpler to implement. Prim’s algorithm is generally more efficient for 'dense' graphs where the number of edges is large. Therefore, Kruskal’s is the preferred choice for graphs with relatively few edges.
In a 'sparse' graph (where the number of edges \(E\) is relatively small and close to \(V\)), Kruskal’s tends to perform better and is often simpler to implement. Prim’s algorithm is generally more efficient for 'dense' graphs where the number of edges is large. Therefore, Kruskal’s is the preferred choice for graphs with relatively few edges.
Not clear enough?
Question 92
Kruskal's algorithm (choosing the best non-cycle edge) is better than Prim's (choosing the best tree edge) when the graph has relatively few edges.
This statement is true because of the way Kruskal’s algorithm scales. Since Kruskal's algorithm operates by sorting all edges at the beginning, its performance is primarily a function of the number of edges \(E\).
In sparse graphs, where the number of edges is much lower than the maximum possible (\(V^2\)), the sorting and union-find operations are very fast. Prim's algorithm, depending on its implementation (like with an adjacency matrix), can be slower in sparse scenarios but excels in dense graphs where it can outperform the edge-sorting requirement of Kruskal's.
In sparse graphs, where the number of edges is much lower than the maximum possible (\(V^2\)), the sorting and union-find operations are very fast. Prim's algorithm, depending on its implementation (like with an adjacency matrix), can be slower in sparse scenarios but excels in dense graphs where it can outperform the edge-sorting requirement of Kruskal's.
Not clear enough?
Question 93
Suppose that a graph G = (V,E) is implemented using adjacency lists. What is the complexity of a breadth-first traversal (BFS) of G?
In a Breadth-First Search (BFS) traversal, every vertex is added to the queue exactly once, and every edge is explored to check for unvisited neighbours.
When using an adjacency list, exploring the edges for a vertex \(u\) takes time proportional to the degree of \(u\). Summing the degrees of all vertices gives twice the number of edges (for undirected graphs). Therefore, the total time spent is proportional to the number of vertices plus the number of edges, resulting in a complexity of \(O(V + E)\). Note: The provided answer B in the source is a common error; D is the standard complexity for this implementation.
When using an adjacency list, exploring the edges for a vertex \(u\) takes time proportional to the degree of \(u\). Summing the degrees of all vertices gives twice the number of edges (for undirected graphs). Therefore, the total time spent is proportional to the number of vertices plus the number of edges, resulting in a complexity of \(O(V + E)\). Note: The provided answer B in the source is a common error; D is the standard complexity for this implementation.
Not clear enough?
Question 94
In a graph implemented using an adjacency list, what specific property of the list structure indicates that a particular vertex is an isolated vertex (a vertex with no edges)?
In an adjacency list representation, the graph is stored as an array of linked lists, where each index in the array represents a vertex. If a vertex is isolated, it means it has no adjacent neighbours. Therefore, the linked list corresponding to that specific vertex's index will be empty.
In programming terms, this is represented by a 'null' or empty pointer at that array position. While all linked lists eventually end in a null pointer, an isolated vertex is identified because its entire list is null from the start, indicating no outgoing or connected edges.
In programming terms, this is represented by a 'null' or empty pointer at that array position. While all linked lists eventually end in a null pointer, an isolated vertex is identified because its entire list is null from the start, indicating no outgoing or connected edges.
Not clear enough?
Question 95
A 'dense' undirected graph is typically characterised by which of the following relationships between the number of vertices (V) and the number of edges (E)?
In graph theory, a graph is considered 'dense' if the number of edges is close to the maximum possible number of edges. For an undirected graph with \(V\) vertices, the maximum number of edges is \(\frac{V(V - 1)}{2}\).
Mathematically, this relationship is expressed as \(E = O(V^2)\). Conversely, a 'sparse' graph is one where the number of edges is much closer to the number of vertices, typically expressed as \(E = O(V)\). Dense graphs are often better represented using adjacency matrices, while sparse graphs are more efficiently stored using adjacency lists.
Mathematically, this relationship is expressed as \(E = O(V^2)\). Conversely, a 'sparse' graph is one where the number of edges is much closer to the number of vertices, typically expressed as \(E = O(V)\). Dense graphs are often better represented using adjacency matrices, while sparse graphs are more efficiently stored using adjacency lists.
Not clear enough?
Question 96
In a directed graph (digraph) \(G = (V, E)\), the graph contains at least one cycle if and only if:
A fundamental theorem in computer science states that a directed graph is acyclic (contains no cycles) if and only if a Depth First Search (DFS) of the graph yields no back edges.
A back edge is an edge \((u, v)\) that connects a vertex \(u\) to one of its ancestors \(v\) in the DFS tree. Because an ancestor is reached before its descendants, a back edge essentially 'loops back' to a previously visited node that is still in the current recursion stack, thereby completing a cycle. The presence of even one back edge is a definitive proof of a cycle.
A back edge is an edge \((u, v)\) that connects a vertex \(u\) to one of its ancestors \(v\) in the DFS tree. Because an ancestor is reached before its descendants, a back edge essentially 'loops back' to a previously visited node that is still in the current recursion stack, thereby completing a cycle. The presence of even one back edge is a definitive proof of a cycle.
Not clear enough?
Question 97
In the context of a Depth First Search (DFS) tree, a 'Back edge' is defined as an edge \((u, v)\) where:
During a DFS traversal, edges are categorised based on the relationship between the source and destination nodes in the resulting forest. A back edge is a non-tree edge \((u, v)\) such that the destination node \(v\) is an ancestor of the source node \(u\).
Since the DFS visits ancestors before descendants, the discovery of an edge leading back to an ancestor indicates that there is a path from \(v\) to \(u\) (via tree edges) and now a direct edge from \(u\) to \(v\), creating a circular path or cycle.
Since the DFS visits ancestors before descendants, the discovery of an edge leading back to an ancestor indicates that there is a path from \(v\) to \(u\) (via tree edges) and now a direct edge from \(u\) to \(v\), creating a circular path or cycle.
Not clear enough?
Question 98
Using the standard ASCII encoding (8 bits per character), how many bits will be required to encode the string "abacdaacacwe"?
The length of the string "abacdaacacwe" is 12 characters.
The calculation is as follows:\[ \text{Total bits} = \text{Number of characters} \times \text{Bits per character} \]\[ \text{Total bits} = 12 \times 8 \]\[ 12 \times 8 = 96 \]Therefore, 96 bits are required to store this string using the standard 8-bit ASCII format.
Note: The provided answer B (128) would only be correct if the string were 16 characters long or if using 16-bit Unicode; for this specific 12-character string in ASCII, 96 is the accurate calculation.
The calculation is as follows:\[ \text{Total bits} = \text{Number of characters} \times \text{Bits per character} \]\[ \text{Total bits} = 12 \times 8 \]\[ 12 \times 8 = 96 \]Therefore, 96 bits are required to store this string using the standard 8-bit ASCII format.
Note: The provided answer B (128) would only be correct if the string were 16 characters long or if using 16-bit Unicode; for this specific 12-character string in ASCII, 96 is the accurate calculation.
Not clear enough?
Question 99
In a Depth First Search (DFS) forest, a 'Cross edge' is defined as an edge \((u, v)\) where:
A cross edge is an edge \((u, v)\) that connects two nodes such that neither node is an ancestor of the other. This typically occurs between nodes in different branches of the same DFS tree or between nodes in entirely different DFS trees within the forest.
Unlike tree, back, or forward edges—which all describe some form of vertical relationship (ancestor/descendant) within a branch—a cross edge represents a horizontal connection between unrelated lineages in the search traversal.
Unlike tree, back, or forward edges—which all describe some form of vertical relationship (ancestor/descendant) within a branch—a cross edge represents a horizontal connection between unrelated lineages in the search traversal.
Not clear enough?
Question 100
Which of the following statements regarding algorithmic properties is true?
Both Dynamic Programming and Greedy algorithms rely on the 'Optimal Substructure' property, which states that an optimal solution to the problem contains within it optimal solutions to sub-problems.
However, they differ in how they make choices. A 'Greedy' algorithm makes a locally optimal choice in the hope that it will lead to a globally optimal solution; this is called the 'Greedy Choice Property'. If a problem has both optimal substructure and the greedy choice property, the local optimum is indeed the global optimum. Dynamic programming, on the other hand, considers multiple sub-problems and overlaps to find the global optimum.
However, they differ in how they make choices. A 'Greedy' algorithm makes a locally optimal choice in the hope that it will lead to a globally optimal solution; this is called the 'Greedy Choice Property'. If a problem has both optimal substructure and the greedy choice property, the local optimum is indeed the global optimum. Dynamic programming, on the other hand, considers multiple sub-problems and overlaps to find the global optimum.
