6.006 Final T/F Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

If the diameter of a connected, unweighted, undirected graph is d, then the depth of any BFS tree from a given node s is at most d.

True, BFS trees store shortest paths, so the worst-case length is d.

Every algorithm that finds a peak (local maximum) in a 1D array A of n elements, in the comparison model, uses Omega(lg n) comparisons in the worst case.

True

If T(n) = c when n ≤ c and T(n) = aT (n/√a) + O(n^2) otherwise, then T(n) = O(n^2 log n)

True

Inserting n elements into an empty dynamic array takes worst case O(n) time

True (amortization)

In any connected, undirected graph with exactly 5 simple cycles (that do not share any edges), DFS will find exactly 5 back edges.

True, DFS will find one back edge for each cycle.

Johnson's and Floyd-Warshall algorithms have the same asymptotic running time when applied to dense graphs

True, O(|V|^3) = O(|V|^2 log |V| + |V||V|^2)

The following problem is in P: given a weighted directed graph G = (V;E;w), vertices s, t in G, and a number l, decide whether the shortest-path weight in G from s to t is ≤ l.

True, can find the shortest path between s and t by running bellman-ford, which is a polynomial-time algorithm

The union of a shortest path from s to u and a shortest path from u to t must also be a shortest path from s to t.

False

Converting an adjacency matrix representation to an adjacency list representation takes O(V + E) time.

Constructing the adjacency list for each vertex takes Theta(V ) time in the worst case, so this conversion might take Theta(V^2).

When solving a single-source shortest-paths problem on a directed graph where all edges have weight 1 or 2, Dijkstra's algorithm will explore nodes in the same order that BFS explores them

False

Given a graph where all edge weights are strictly greater than -3, a shortest path between vertices s and t can be found by adding 3 to the weight of each edge and running Dijkstra's algorithm from s.

False, Dijkstra may just reach something else first (use counterexample)

A perfect hash table supports both finding and inserting an element into the table, each in worst-case O(1) time.

False, a perfect hash has worst-case O(1) find, but inserting an element could require a linear time to rebuild.

A set S of two-dimensional points in the plane has a convex hull with x vertices; after adding another point to S, the convex hull has y vertices. We must have y ≥ x.

False, adding a point might decrease the number of vertices on the convex hull.

In every directed acyclic graph, BFS and DFS visit the vertices in the same order.

False, consider any tree - BFS will visit these in level order, while DFS will probe between levels.

While running depth-first search, if the discover time of a node u is before the discover time of node v, then u must be an ancestor of v.

False, could just happen to reach a node on one branch before a node on another branch.

Let D be the following decision problem: given a directed graph G with nonnegative weights, two vertices s and t, and an integer K, determine whether the shortest path from s to t is less than K in length. D cannot be NP-complete.

False, don't know if P = NP.

A noisy transmission line corrupts each transmitted bit of an input binary source with 10% probability by setting it to 0. Then for any binary source transmitted, the corrupted signal will have lower entropy than the input source.

False, for example, if the input source is all ones, then adding zeros will yield a corrupted signal with higher entropy

If an edge can still be relaxed after running Bellman-Ford on a directed graph (i.e. it does not satisfy the triangle inequality), then either this edge has negative weight, or it must be part of a negative cycle

False, it might be the case that if an edge can be relaxed, it's on a path that includes a negative cycle, but it doesn't need to be on the cycle, nor does it need to have negative weight.

Consider the forest (vertex-disjoint set of trees) returned by a complete run of DFS on a directed graph. The number of trees in this forest will always be the same, regardless of the order in which you visit nodes in the outermost loop of DFS.

False, one counterexample is running a DFS along a long chain of directed edges vs. going backwards on this same chain.

You have a magic machine that can solve instances of an NP-Complete problem in constant time. If you can design an algorithm that uses the machine to solve another decision problem A in polynomial time, then this implies that problem A is also NP-Complete.

False, reduction in wrong direction; reducing A to NP-Complete problem only proves that A is no harder than NP-Complete problem, i.e. A is in NP.

Given an unweighted directed graph having only one source vertex s having no incoming edges, a depth-first search from s will always generate a DFS tree containing a longest simple path in the graph.

False, the DFS can choose to first search any unvisited neighbor, not necessarily the one that is on the longest simple path.

You are given a hash table implemented using a universal hash function where collisions are resolved via chaining. If you insert n elements into the empty hash table, the length of any chain can be at most O(log n).

False, the length of a chain might be linear in the worst case

Recall that a simple path is a path that visits no vertex more than once. In any (unweighted) undirected graph G = (V;E), the number of simple paths between two vertices is at most 2^V.

False, the number of simple paths can be much higher

Assume we are running Dijkstra's algorithm from a vertex s in a positive-weighted graph G. If the shortest path between s and some vertex v has exactly k edges, then v.d = delta(s; v) after k + 1 EXTRACT-MIN operations.

False, this is not the invariant for Dijkstra.

The diameter of an unweighted AVL tree with n nodes is at most 2 log n + 2

False. An AVL tree does not have height log n, it has height O(log n). The height of an AVL tree might be higher: in the worst case, it's around 1:44 log n. This leads to a larger diameter.

For all weighted directed graphs G = (V;E;w), Dijkstra's algorithm is asymptotically faster than an O(V^1.3)-time algorithm.

False. Consider a complete graph on V nodes. Then Dijkstra's algorithm takes Omega(V^2) time.

Given a directed acyclic graph having positive edge weights and only one source vertex s having no incoming edges, running Dijkstra's from s will remove vertices from the priority queue in a topological sort order.

False. Counter example: a graph on vertices s, t, v, with directed weighted edges w(s; t) = 1, w(s; v) = 2, and w(v; t) = 1. Dijkstra from s processes vertices in order (s; t; v), while topological sort order is (s; v; t).

If the diameter of a connected, unweighted, undirected graph is d, then the depth of any DFS tree from a given node s is at most d.

False. DFS does not find shortest paths. For example, consider a complete graph: even though the diameter is 1, a DFS tree will have depth V - 1 because it visits all the vertices in some order

Heapsort runs in O(n) time on a sorted array of n elements.

False. Every call to EXTRACT-MAX takes O(lg n), and since heapsort requires O(n) EXTRACT-MAX calls, its runtime complexity is O(n lg n)

You implement a hash table using some specific hash function h(k), and then insert a sequence of n integers into the hash table. Then looking up whether a queried integer is stored in this hash table will take expected O(1) time.

False. Expected bounds are only valid when choosing a hash function randomly from a universal hash family.

In any connected, undirected graph with exactly 5 simple cycles (that do not share any edges), there are at most 10 simple paths between every pair of vertices

False. For each cycle, you might have two options for which direction to take. In the worst case, this is 2^`5 = 32 paths between two vertices.

If G has a valid topological ordering, and that topological ordering is unique, it follows that E = O(V )

False. For example, consider the case where V - 1 vertices are fully connected, and the final node has no neighbors.

If Bellman-Ford from a given s in V always finds the correct shortest-path weights after 1 iteration (regardless of edge ordering), it follows that E = O(V )

False. For example, if s connects to every v in V with weight 1, and all other V (V - 1) - V edges higher weights, then the shortest paths from s have one edge but E = o(V ).

Recall that Johnson's algorithm reweights edges by creating a new node s, connecting s to every other vertex v with an edge (s; v) of weight 0, and running Bellman-Ford from s. The algorithm would still work if, instead, we picked an arbitrary existing node u, and added an edge (u; v) of weight 0 to every other vertex v for which edge (u; v) did not already exist.

False. If the selected node u was part of a negative weight cycle in the original graph, then running Bellman-Ford from u will not be able to find finite node potentials for the Johnson's transformation, and thus we will not be able to run Dijkstra's from every node.

Recall that the Floyd-Warshall algorithm involves three nested for loops, iterating through intermediate, start, and destination vertices, respectively. If we remove the middle loop and just use a fixed start vertex, then we obtain an O(V^2)-time single-source shortest-paths algorithm.

False. If we fix the start vertex, then we will never update paths starting from an intermediate vertex. For this reason, we won't find the shortest paths

When using an adjacency matrix graph representation, relaxing all the edges in a graph G(V;E) can be done in O(E) time

False. In an adjacency matrix graph representation passing through all the edges of a graph takes always O(V^2) time, even if E « V^2

If Johnson's algorithm always produces the correct all-pairs shortest-path weights, then G must have at least one edge with positive weight

False. It could be a DAG with all negative-weight edges.

If the DFS tree of G has O(V) back edges, it follows that E = O(V)

False. Removing the O(V ) back edges makes the graph a DAG, but a DAG doesn't necessarily satisfy E = O(V )

Any binary search tree on n nodes can be transformed into an AVL tree using O(log n) rotations.

False. Since any rotation changes height of any node by at most a constant, a chain of n nodes would require at least Omega(n - log n) rotations.

Given an array of n integers representing a binary min-heap, one can find and extract the maximum integer in the array in O(log n) time.

False. The maximum element could be in any leaf of the heap, and a binary heap on n nodes contains at least Omega(n) leaves.

The rolling hash technique enables us to compute and compare hashes of two arbitrary strings, each of length l, in O(1) time.

False. The rolling hash technique applies only to situation in which we already have computed a hash of a string and want to compute a hash of the same string after removing or adding a letter to it.

If f(c) = O(1) for a constant c and f(n) = 4f(n=2) + Theta(n^2) for n > c, and g(c) = O(1) for a constant c and g(n) = 8g(n/2) + Theta(n) for n > c, then f = Omega(g).

False. f is Theta(n^2 log n) and g is Theta(n^3), by Master theorem.

If there exist functions f; g; h such that f = O(g) and g = Omega(h), then f = Theta(h)

False; for example, f = n^2, g = n^3, h = n

An AVL tree with 2^k nodes has height at most k+1

False; height of an ABL tree with n nodes is approx. 1.44 logn worst case

Let D be the following decision problem: given a directed graph G with nonnegative weights, two vertices s and t, and an integer K, determine whether the shortest path from s to t is less than K in length. D is in P.

True, can use Bellman-Ford or Dijkstra

Let D be the following decision problem: given a directed graph G with nonnegative weights, two vertices s and t, and an integer K, determine whether the shortest path from s to t is less than K in length. D is in NP.

True, can verify the path in Theta(V+E) time

The following problem is in P: given a weighted directed graph G = (V;E;w), vertices s, t in G, and a number l, decide whether there is a simple path in G from s to t of weight ≥ l.

True, given a path between s and t it is easy to verify in polynomial time that it is both simple, and has weight ≥ l.

If a graph contains no negative-weight cycles, there exists an ordering of edges such that Bellman-Ford computes shortest paths by relaxing each edge at most once

True, if there are not negative weight cycles, there exists a directed shortest path tree. Relaxing in a topological sort order of that tree will only relax each edge once

Any comparison sort on n items runs in Omega(log(n!))

True, log(n!) = Theta(n log n)

When sorting n integers between -n^10 and n^10, radix sort runs (asymptotically) faster than insertion sort.

True, radix sort can run in Theta(n) while insertion sort takes O(n^2)

The Floyd-Warshall algorithm involves looping through intermediate, start, and destination vertices (in that order). Alyssa P. Hacker accidentally implemented Floyd-Warshall to loop through the intermediate, destination, and start vertices (in other words, she switched the second and third loop). Alyssa's modified version of Floyd-Warshall still produces the correct all-pairs shortest paths

True, start and destination vertices are symmetric, so switching them does not affect the result

A set S of two-dimensional points in the plane has a convex hull with area x; after adding another point to S, the convex hull has area y. We must have y ≥ x.

True, the area of the convex hull cannot decrease

Given a connected undirected graph, there exists a linear time algorithm that returns a node that, when removed, disconnects the graph, or returns that such a node does not exist

True, use modified DFS to find articulation nodes

Assume that a data structure supports some operation in O(T) amortized time. Consider now a situation in which we initialize the data structure and then make k calls to that operation. The worst-case time needed to serve the first of these calls is O(T).

True.

If we run Dijkstra's algorithm on a graph in which there is a single negative weight edge outgoing from the source s, then all the distances computed by this algorithm will be correct.

True. As this negative-weight edge e = (s; v) is outgoing from the sources and all other edges have non-negative length, the distance of this edge's other endpoint v from s is equal to the (negative) weight we of that edge e. So, the first round of relaxations of edges outgoing from s will set d[v] = w_e < 0. Consequently, v will be the first vertex (after s) pulled out of the priority queue Q and its distance from s will be computed correctly. As the edge e will never take part in any further computations and all the remaining edges have non-negative weights, we know that the rest of distances will be computed correctly too.

Given an array of n key-value pairs, one can construct a hash table mapping keys to values in expected O(n) time by inserting normally into the hash table one at a time, where collisions are resolved via chaining. If the pairs have unique keys, it is possible to construct the same hash table in worst-case O(n) time.

True. Because keys are unique, we do not have to check for duplicate keys in chain during insertion, so each insert can take worst-case O(1) time.

When running Johnson's algorithm, we create a node s, connect it to every vertex v in V , and run Bellman-Ford from s to produce our height function (also known as the "potential function") h(v). As long as the edges from s to v in V have finite weight (that need not be the same for all edges), Johnson's algorithm will produce the correct all-pairs shortest paths on a directed graph with no negative weight cycles

True. Because the edges from s to V are directed, they will not create any cycles from s, so it's okay if they have negative weight. In addition, regardless of what these edge weights are, as long as the graph is connected Bellman-Ford will produce finite delta(s; v) values that satisfy the triangle inequality.

If there is a polynomial time algorithm to determine whether an unweighted graph contains a Hamiltonian path, then there is also a polynomial time algorithm to determine whether a weighted graph contains a simple path with weight greater than or equal to k.

True. Both problems are NP-Hard and in NP, so if you can solve one of them in polynomial time, you can solve any problem in NP in polynomial time, including the other problem.

Consider a connected, undirected graph with more edges than vertices and only negative edge weights. Then, for any start node, Bellman-Ford necessarily detects a negative-weight cycle.

True. If there are more edges than vertices, there must be a cycle in the graph (this is not true for directed graphs). Because all edge weights are negative, there must be a negative cycle. Because the graph is connected, Bellman-Ford will detect this cycle no matter where it starts in the graph.

Consider the forest (vertex-disjoint set of trees) returned by a complete run of DFS on an undirected graph. The number of trees in this forest will always be the same, regardless of the order in which you visit nodes in the outermost loop of DFS

True. In an undirected graph, there is always a separate tree for each connected component. This number is the same, regardless of the order in which DFS visits vertices.

The problem of determining whether an undirected graph contains as a subgraph a complete graph on k vertices is in NP.

True. Providing a subset of k vertices is a O(k) polynomial size certificate which can be checked for completeness in O(k^2) polynomial time.

If G(V;E) is a directed graph in which all the edge weights are positive integers bounded by a fixed constant, then all shortest paths from a single source can be computed in O(V + E) time.

True. Shortest path distances in transformed unweighted graphs are the same as in the original graph and the unweighted graph has at most V' = V + C* E vertices and E' = C 8 E edges. Therefore, we can computer shortest path distances in it (and the original graph) using BFS in O(V' + E') = O(V + C*E + C*E) + O(V + E)

When running Dijkstra's algorithm on sparse graphs (i.e. E = O(V )), binary heaps and Fibonacci heaps have the same time complexity

True. When E = O(V ), we have O(E log V + V log V ) = O((E + V ) log V ) = O(V log V )

An array with exactly two peaks can be sorted in Theta(n) time

True; perform three way merge after identifying peaks


Kaugnay na mga set ng pag-aaral

DMS 132 Chapter 63 Fetal abdomen

View Set

Chapter 11: Nonprofits and Corporate Social Responsibility

View Set

Security Awareness Applying Practical Security in Your World, Chapter 1 terms

View Set

Food Protection Manager Certification Examination

View Set

World History and Geography Final

View Set

Chapter 12 - Reinsurance; Industry Organizations; The Customer

View Set

TRADE DISCOUNT AND CASH DISCOUNT

View Set

Chapter 2: Characteristic of Culture

View Set

CRM Exam - Part 2.B.2 - Risk Assessments and Mitigation

View Set