Test 2 Questions Flashcards

1
Q

A graph G = (V, E) is sparse if

A

E = V

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

For a priority queue implemented as a binary heap, the two operations of inserting and removing an element (and maintaining the heap property) each have ____ complexity, where n is the size of the priority queue.

A

O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Prim’s algorithm can find a minimal spanning tree of a graph only ___.

A

If the graph is undirected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

T/F

There is an algorithm that tests whether a graph is acyclic in worst-case complexity O(V+E)

A

TRUE

DFS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Breadth-First Search uses a

A

QUEUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

T/F

An optimal solution to the fractional knapsack problem can be found by a greedy algorithm, whereas an optimal solution to the 0/1 knapsack problem cannot

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In an undirected graph with unit edge costs, a shortest path tree is always ___.

A

a shortest path between the two vertices in the full graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Bellman-Ford solves ___

A

The single-source shortest path problem with negative weight edges but no negative weight cycles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Time Complexity of Bellman-Ford :

A

Θ(V * E)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The single source shortest path in an acyclic graph can be solved in ___ time, even if the graph has negative cost weight.

A

Θ(V + E)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

T/F

The single-source-longest path problem in a graph is just as easy to solve as the single-source shortest path problem in the same graph.

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe one important similarity and difference between “Divide and Conquer” and Dynamic Programming

A

Similarity: Both recursively divide the problem into subproblems and solve those subproblems.

D/C solves each subproblem and never visits that subproblem again.
DP, the subproblem may overlap, so the subproblem’s results are stored in a table for later use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the asymptotic time complexity of topological sort?

A

O(V+E)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is it possible to perform a topological sort of an undirected graph? Explain why.

A

No.

Undirect graphs may produce cycles which is not allowed in topological sort.

Also, you need direction/order for top sort.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

T/F

Prim’s and Dijkstra’s have the same time complexity.

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Prim’s and Dijkstra’s time complexity when they are used to solve a problem in a dense graph, and the priority queue is implemented as an UNSORTED ARRAY

17
Q

Describe at least 2 properties that are characteristic of any dynamic programming algorithm.

A
  1. Has recurrance relationship.
  2. Has table, each entry the distance we are optimizing and a pointer.
  3. Traceback property with pointers.
18
Q

Most efficient algorithm for solving Single-Source shortest path problem in an unweighted sparse graph.

A

Breadth First Search

O(V+E)

19
Q

Most efficient algorithm for single-source shortest path problem in a graph with non-negative edge weights

A

Dijkistra’s

O(V log V) or
O(E log V) if E = V

20
Q

Most efficient algorithm for single source shortest path in a graph with negative weights but no negative weight cycles

A

Bellman Ford

O(V*E) or
O(V^2) if E = V

21
Q

What is meant by a strongly connected component of a directed graph?

A

That every vertices in the subgraph can access any other vertice in that same subgraph.

22
Q

What is the asymptotic complexity of the best algorithm for finding the strongly connected components of a directed graph?

A

DPS

O(V+E)